IO流-文件的复制
import java.io.*;
public class test3 {
public static void main(String[] args) throws IOException {
File src = new File("G:\\1\\1.txt");
File file = new File("G:\\1\\a");
copyFile(src,file);
}
public static void copyFile(File srcFile, File destDir) throws IOException {
File destFile = new File(destDir, srcFile.getName());
FileInputStream fileInputStream = new FileInputStream(srcFile);
FileOutputStream fileOutputStream = new FileOutputStream(destFile);
byte[] bytes = new byte[1024];
int len;
while ((len = fileInputStream.read(bytes)) !=-1) {
fileOutputStream.write(bytes, 0, len);
}
fileInputStream.close();
fileOutputStream.close();
}
}