我有一个这样的BufferedReaderBufferedWriter(评论员要求查看整个代码)来测试一些培训页面:

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new FileReader("inputFile.in"));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("inputFile.out")));

        int N = Integer.parseInt(bf.readLine());

        int[] dayCount = {0, 0, 0, 0, 0, 0, 0}; //Line 19

        int day = 0;
        for (int year = 1990; year < 1990 + N; year++) {
            for (int month = 1; month <= 12; month++) {
                if (month == 2) {
                    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
                        dayCount[(day + 13) % 7]++;
                        day += 29;
                    } else {
                        dayCount[(day + 13) % 7]++;
                        day += 28;
                    }
                }
                else if (month == 4 || month == 6 || month == 9 || month == 11) {
                    dayCount[(day + 13) % 7]++;
                    day += 30;
                }
                else {
                    dayCount[(day + 13) % 7]++;
                    day += 31;
                }
            }
        }
        for (int i = 0; i < 7; i++) {
            if (i < 6)
                pw.print(dayCount[(i + 6) % 7] + " ");
            else
                pw.print(dayCount[(i + 6) % 7]);
        }
        pw.println();
        pw.close();
    }


我目前正在使用VS Code,运行代码时,出现一个弹出窗口(我不知道如何重现),该弹出窗口的内容与“ Marketplace具有可帮助的扩展名”类似。文件扩展名。”我查看了扩展名,然后搜索了Google,找不到.in.out文件的扩展名。我想要一个的原因是由于抛出了错误,即使我在当前工作目录中创建了文件也是如此。这是错误:

Exception in thread "main" java.io.FileNotFoundException: inputFile.in (The system cannot find the file specified)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:212)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:154)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:109)
        at java.base/java.io.FileReader.<init>(FileReader.java:60)
        at iotests.iotests.main(ioTests.java:19)


我已经在上面评论了第19行。

最佳答案

这是因为您的文件扩展名很奇怪,VSCode不知道可以打开哪个程序,因此,它只是提示您在marketPlace中找到某个程序可以打开它。因此,请停止使用“ inputFile.in”,“ inputFile.out”,“。in”,“。out”的名称
文件扩展名,只是“ .txt”。

关于java - .out和.in扩展名的“系统找不到指定的文件”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61220125/

10-09 07:09
查看更多