小编典典

java.io.FileNotFoundException:in.txt,(系统找不到指定的文件)

java

我收到以下错误

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)

但我可以肯定地说,我已经在src,bin和根目录下创建了一个in.txt文件。我还尝试在主要参数中指定完整目录,但仍然无法正常工作。为什么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);
        }

    }
}

阅读 510

收藏
2020-11-30

共1个答案

小编典典

我获取了您的代码,并使用以下命令行参数执行了该代码:

in.txt out.txt

它完全没有问题。检查您的命令行。

2020-11-30