采用边读边写的方式进行拷贝
import Inputstream.FileInputStream_;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
public class CopyFileExercise {
public static void main(String[] args) throws IOException {
String srcPath = "D:\\娱乐、日常\\图片\\壁纸\\bs.jpg";
String dercPath = "D:\\Temp\\derc.jpg";
FileInputStream fileInputStream = new FileInputStream(srcPath);
FileOutputStream fileOutputStream = new FileOutputStream(dercPath);
int readlength = 0;
byte[] byts = new byte[1024];
try {
while ((readlength = fileInputStream.read(byts)) != -1) {
fileOutputStream.write(byts, 0, readlength);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
fileInputStream.close();
fileOutputStream.close();
}
}
}