Exception in thread main java.nio.file.NoSuchFileException


Exception Stack:
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
java.nio.file.NoSuchFileException
java.nio.file.NoSuchFileException


















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap