JB Header
Java - How to resolve error java.nio.file.NoSuchFileException
This quick coding tip explains how to resolve error java.nio.file.NoSuchFileException when using NIO API in Java.

If you are getting the following exception at runtime -
java.nio.file.NoSuchFileException: C:\JavaBrahman\LEVEL11
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53)
at sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38)
at sun.nio.fs.WindowsFileSystemProvider.readAttributes(WindowsFileSystemProvider.java:193)
at java.nio.file.Files.readAttributes(Files.java:1737)
at java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:219)
at java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:276)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:322)
at java.nio.file.Files.walkFileTree(Files.java:2662)
at java.nio.file.Files.walkFileTree(Files.java:2742)
at com.javabrahman.corejava.RecursiveFileVisitor.main(RecursiveFileVisitor.java:39)
...
Resolution for the java.nio.file.NoSuchFileException error
  • This error occurs most commonly when a file name, directory name or file path has been incorrectly specified when using the file handling classes of java.nio.file package.
  • You need to closely check the file path you have given in the Java class written by you. This file or directory path will be printed on the top line of the error stack trace as well. Just as C:\JavaBrahman\LEVEL11 is printed at the top of the above stack trace.
  • The errant Java class will be present in the middle of the stack trace, between the NIO package's internal calls, along with the error causing line number. In the above stack trace the error causing file is - (RecursiveFileVisitor.java:39).
  • Also note that, java.nio.file.NoSuchFileException is most likely to be thrown when creating an instance of java.nio.file.Path instance with an incorrect directory path or file name.