Here you can find the source of copyFileUsingStream(String source_path, String dest_path)
public static void copyFileUsingStream(String source_path, String dest_path)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyFileUsingStream(String source_path, String dest_path) { File source = new File(source_path); File dest = new File(dest_path); InputStream is = null;//from w w w. j a va2 s . c o m OutputStream os = null; try { is = new FileInputStream(source); os = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } } catch (FileNotFoundException e) { System.out.println( "ERROR: FileUtils: copyFileUsingStream: File not found! exception was: " + e.toString()); } catch (IOException e) { System.out.println( "ERROR: FileUtils: copyFileUsingStream: Error in the I/O! exception was: " + e.toString()); } finally { try { is.close(); os.close(); } catch (IOException e) { System.out.println( "ERROR: FileUtils: copyFileUsingStream: Error while closing the stream! exception was: " + e.toString()); } } } }