Proses ini akan melakukan copy atau penggandaan file, misal anda mempunyai file A dan ingin di-copy ke folder lain atau bahkan ke komputer lain.
Script Keseluruhan :
public void copyfile(){Semoga tulisan ini bermanfaat.
try{
File f1 = new File("d:\\iniFileAsli.txt");
File f2 = new File("d:\\folderTujuan\\iniHasil.txt");
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
}
catch(FileNotFoundException ex){
System.out.println(ex.getMessage() + " in the specified directory.");
System.exit(0);
}
catch(IOException e){
System.out.println(e.getMessage());
}
}