Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Stefan Wendelmann
Added: May 24, 2018 12:47 PM
Views: 13
Tags: copy file java
  1.   /**
  2.    * Kopiert ein file mittels Steam (Schnelle Mehtode).
  3.    *
  4.    * @param source
  5.    * @param dest
  6.    * @throws IOException
  7.    */
  8.   private void copyFileUsingStream(File source, File dest) throws FileNotFoundException, IOException
  9.   {
  10.     // TODO LaufId impl.
  11.     File tmp = File.createTempFile(laufId, ".tmp", dest.getParentFile());
  12.  
  13.     byte[] buffer = new byte[1024];
  14.     int len;
  15.     FileInputStream fis = new FileInputStream(source);
  16.     FileOutputStream fos = new FileOutputStream(tmp);
  17.     while ((len = bis.read(buffer)) > -1)
  18.     {
  19.       bos.write(buffer, 0, len);
  20.     }
  21.     bis.close();
  22.     fis.close();
  23.     bos.close();
  24.     fos.close();
  25.     tmp.renameTo(getUniqueFilename(dest));
  26.   }