我收到错误消息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();
}
}