close

[Solved] How to solve the java.nio.file.NoSuchFileException?

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the following error How to solve the java.nio.file.NoSuchFileException? in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

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

Today I am facing the following error How to solve the java.nio.file.NoSuchFileException? in Java.

How To Solve the java.nio.file.NoSuchFileExceptionError ?

  1. How To Solve the java.nio.file.NoSuchFileExceptionError ?

    To Solve the java.nio.file.NoSuchFileExceptionError If your file("result.csv") in the src directory, you should use the “src/result.csv” instead of “result.csv”.

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

    To Solve the java.nio.file.NoSuchFileExceptionError If your file("result.csv") in the src directory, you should use the “src/result.csv” instead of “result.csv”.

Solution 1

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

Solution 2

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.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read