英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论