我正在学习一些关于 udemy 的课程。我正在学习 Paths ,但我无法让 Paths.get 工作。
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
Path filePath = Paths.get("C:\\OutThere.txt");
printFile(filePath);
}
private static void printFile(Path path){
try(BufferedReader fileReader = Files.newBufferedReader(path)){
String line;
while((line = fileReader.readLine())!=null){
System.out.println(line);
}
}catch(IOException e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
文件存在,名称正确且位于 C 盘上。我究竟做错了什么?
java.nio.file.NoSuchFileException: C:\OutThere.txt
at com.bennydelathouwer.Main.main(Main.java:16)