我目前正在我的 cpe 课程的实验室工作,我们必须创建一个简单的程序,从 .txt 文件中扫描字符串并将它们打印到不同的 .txt 文件中。到目前为止,我已经制定了基本程序,但是尽管我拥有所有必要的文件,但我的异常仍然被抛出。谁能帮我调试?
import java.io.*;
import java.util.*;
public class FileIO {
public static void main(String args[]) {
try {
File input = new File("input");
File output = new File("output");
Scanner sc = new Scanner(input);
PrintWriter printer = new PrintWriter(output);
while(sc.hasNextLine()) {
String s = sc.nextLine();
printer.write(s);
}
}
catch(FileNotFoundException e) {
System.err.println("File not found. Please scan in new file.");
}
}
}