How to solve the java.nio.file.NoSuchFileException?

The problem is that your default directory at application startup is not what you think it is. Try adding the following line to your code, just after you create the path:

public static void main(String [] args) {
    int i=0;
    String filename="result.csv";
    Path pathToFile = Paths.get(filename);
    System.out.println(pathToFile.toAbsolutePath());

That way, you'll see exactly where it is looking for the file.

How to fix it is your decision. You can use a full path spec instead of just a filename, or put the filename in a special "Resources" directory and reference it using a relative path, or move the file to wherever your default directory is.


If your file("result.csv") in the src directory, you should use the "src/result.csv" instead of "result.csv".

Tags:

Java

File