Exception in thread "main" java.nio.file.NoSuchFileException: /Users/c2c/lambdas/sample-file.txt
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:182)
at java.base/java.nio.channels.FileChannel.open(FileChannel.java:292)
at java.base/java.nio.channels.FileChannel.open(FileChannel.java:345)
at java.base/java.nio.file.Files.lines(Files.java:4038)
at java.base/java.nio.file.Files.lines(Files.java:4130)
at JavaFilesWithStreamExample.main(JavaFilesWithStreamExample.java:19)
Reason for NoSuchFileException exception:
The reason for "no such file exception" is either the file that you are trying to process is either missing, misspelled or an incorrect path is provided for the file.
Fix NoSuchFileException exception:Make sure that,
- Print the path in the code and check if it is really present,
- File name provided is correct (check file extension as well)
- File path (relative/absolute) is provided correctly
- Check the case of the file name/path

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!