一个有关java的问题,请各位Java高手告诉我一下

2024-12-12 15:44:34
推荐回答(1个)
回答1:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Scanner;

public class CopyFile {

public static void main(String[] args) throws Exception {
System.out.print("请输入源文件位置:");
File f1 = new File(new Scanner(System.in).next());
if (!f1.exists()) {
System.out.println("原文件不存在。。。");
System.exit(1);
}
System.out.print("请输入目标文件文件位置:");
File f2 = new File(new Scanner(System.in).next());
InputStream input = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2);
if (input != null && out != null) {
int temp = 0;
while ((temp = input.read()) != -1) {
out.write(temp);
}
}
input.close();
out.close();
}

}
lz给你个参考。。。