没有这样的文件或目录,但文件存在。

huangapple go评论69阅读模式
英文:

No such file or directory but the file exists

问题

import java.util.Scanner;
import java.io.*;

public class NumberTester {
    public static void main(String[] args) throws IOException, FileNotFoundException{
        Boolean prime;
        Boolean even;
        Boolean repeatsDigits;
        int num;
        Scanner inputFile = new Scanner(new File("numbers2.txt"));
        PrintWriter outputFile = new PrintWriter("numberSummary.txt");
        outputFile.printf("%15s", "Repeat\n");
        outputFile.printf("Number");
        outputFile.printf("%8s", "Digits");
        outputFile.printf("%8s", "Even");
        outputFile.printf("%8s", "Prime");

        num = inputFile.nextInt();
        
        outputFile.close();
    }
}
英文:

I'm not completely done with this program but after running it IntelliJ keeps telling me no file exists even though it does. What am I doing wrong.

import java.util.Scanner;
import java.io.*;


public class NumberTester {
    public static void main(String[] args) throws IOException, FileNotFoundException{
        Boolean prime;
        Boolean even;
        Boolean repeatsDigits;
        int num;
        Scanner inputFile = new Scanner(new File("numbers2.txt"));
        PrintWriter outputFile = new PrintWriter("numberSummary.txt");
        outputFile.printf("%15s", "Repeat\n");
        outputFile.printf("Number");
        outputFile.printf("%8s", "Digits");
        outputFile.printf("%8s", "Even");
        outputFile.printf("%8s", "Prime");

        num = inputFile.nextInt();
        
        outputFile.close();

   

答案1

得分: 1

问题出在对文件的相对路径上。在这种情况下,我需要在numbers2.txt之前添加一个“/”,因为程序与该文件在同一个目录中。

英文:

The problem was with the relative path to the file. In this case, I needed to add a "/" before the numbers2.txt as the program was in the same directory as this file.

huangapple
  • 本文由 发表于 2020年9月24日 11:38:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/64039175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定