이에서 방금 경로가 참조하는 파일이있는 경우 toRealPath()가 절대 경로를 제공해야한다고 읽었습니다. 여기 toRealPath(), IO/NIO 패키지 Java
같은 튜토리얼에서 미리보기입니다 : 그래서try {
Path fp = path.toRealPath(); } catch (NoSuchFileException x) {
System.err.format("%s: no such" + " file or directory%n", path);
// Logic for case when file doesn't exist. } catch (IOException x) {
System.err.format("%s%n", x);
// Logic for sort of file error. }
, 지금은 예 (Path inputPath = Paths.get("/home/user/Desktop/indeed.txt"
)에 대한 내 바탕 화면에있는 기존 파일을 사용하는 경우; 그것은 존재하지 않는다면 저에게 예외를줍니다. 이 문제의 원인은 무엇입니까? 미리 감사드립니다.
EDIT : NoSuchFileException이 발생합니다.
java.nio.file.NoSuchFileException: /home/user/Desktop/indeed.txt
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixPath.toRealPath(UnixPath.java:833)
at Pathss.main(Pathss.java:25)
파일이 존재하고 올바른 경로/위치에 있음 – Rollerball