【发布时间】:2020-10-25 09:45:09
【问题描述】:
我收到错误 Exception in thread "main" java.nio.file.NoSuchFileException,但我确定文件存在于给定位置 C:\\Users\\Admin\\Desktop\\Java.txt"。
为什么我还是会收到这个错误?
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Scanner;
public class ReadData {
public static void main(String[] args) throws IOException {
Scanner file = new Scanner(Paths.get("C:\\Users\\Admin\\Desktop\\Java.txt", "UTF-8"));
int int_value;
while ((file.hasNextInt())) {
int_value = file.nextInt();
System.out.println("Data:" + int_value);
}
file.close();
}
}
【问题讨论】:
-
"no such file" 错误提示您尝试使用的文件不存在。你觉得有吗?
-
VSC 和 Elipse IDE 都出现过,我昨天刚下载。如何配置它
-
Umm ...在文件系统中查看“C:\\Users\\Admin\\Desktop\\Java.txt”是否有文件。如果它不存在 在那个位置 ...这就是您的应用程序找不到它的原因!可能的解决方案:1)创建文件,或 2)更正程序中的路径。
-
我有检查器,并且我之前已经插入了确切的地址文件。但是还是报错
-
好的,我误会了一个无法用语言解释的问题。无论如何非常感谢你