کد: انتخاب همه
package com;
import java.io.*;
/**
* Created by Bahador on 6/10/2017.
*/
public class FileCopy {
public static void main(String[] args)throws Exception {
FileCopy fileCopy = new FileCopy();
File file1 = new File("C:\\ROOT\\a.jpg");
File file2 = new File("C:\\ROOT\\b.jpg");
fileCopy.copyFileUsingFileStreams(file1, file2);
}
private void copyFileUsingFileStreams(File source, File dest)
throws IOException {
InputStream input = new FileInputStream(source);
OutputStream output = new FileOutputStream(dest);
try {
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
} finally {
input.close();
output.close();
}
}
}