我收到以下錯誤java.io.FileNotFoundException:in.txt,(該系統找不到指定的文件)
java.io.FileNotFoundException: in.txt, (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at FileTest.main(FileTest.java:50)
但林肯定的是,我已經下創建的文件in.txt src,bin和根目錄。我也嘗試在我的主要參數中指定完整的目錄,但仍然無法正常工作。爲什麼Eclipse沒有選擇它?
import java.io.*;
public class FileTest {
public static void main(String[] args) {
try {
String inFileName = args[0];
String outFileName = args[1];
BufferedReader ins = new BufferedReader(new FileReader(inFileName));
BufferedReader con = new BufferedReader(new InputStreamReader(System.in));
PrintWriter outs = new PrintWriter(new FileWriter(outFileName));
String first = ins.readLine(); // read from file
while (first != null) {
System.out.print("Type in a word to follow " + first + ":");
String second = con.readLine(); // read from console
// append and write
outs.println(first + ", " + second);
first = ins.readLine(); // read from file
}
ins.close();
outs.close();
} catch (IOException ex) {
ex.printStackTrace(System.err);
System.exit(1);
}
}
}
您需要將其放在項目目錄IIRC的src目錄之外。 – nhahtdh
@nhahtdh是的,我已經做到了,但仍然運氣... – user133466
如何運行你的Java程序?我看到文件名是通過args參數接收的。 –