public class Test {
public static void main(String[] args) throws IOException {
String sourcePath = "D:/exam.doc";
String destPath = "E:/exam.doc";
int length = -1;
byte[] arrs = new byte[1024];
File sourFile = new File(sourcePath);
FileInputStream inputStream = new FileInputStream(sourFile);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
File destFile = new File(destPath);
FileOutputStream outputStream = new FileOutputStream(destFile);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
while ((length = bufferedInputStream.read(arrs)) != -1) {
bufferedOutputStream.write(arrs, 0, length);
}
bufferedOutputStream.close();
outputStream.close();
bufferedInputStream.close();
inputStream.close();
System.out.println("文件复制成功!");
}
} |