import java.io.*;
/**
* 利用IO實現文件複製
*/
public class FileCopy {
public static void main(String[] args) {
File source = new File("D:\\source.jpg");
File target = new File("D:\\target.jpg");
try(
FileInputStream fileInputStream = new FileInputStream(source);
FileOutputStream fileOutputStream = new FileOutputStream(target);
) {
byte[] buffer = new byte[1024];
int byteRead;
while ((byteRead = fileInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, byteRead);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}