---
title: "How do you fix java.nio.file.NoSuchFileException?"
description: "NoSuchFileException means the path does not exist from the program's working directory. Print the absolute path, check the location, and create missing folders."
url: "https://bugsee.com/answers/java/java-nio-file-nosuchfileexception/"
---

# How do you fix java.nio.file.NoSuchFileException?

The path you gave does not exist from the program's working directory. Print `path.toAbsolutePath()` to see what Java is really looking for, then fix the path or create the file.

```java
Path path = Path.of("data/config.json");
System.out.println(path.toAbsolutePath());   // where Java is really looking
System.out.println(Files.exists(path));

// Writing: create the parent folders first
Files.createDirectories(path.getParent());
Files.writeString(path, "{}");
```

- Relative paths start at the working directory, which is the project root in many IDEs but a different folder when you run a JAR or a build tool.
- Files inside your project's resources are on the classpath, not the file system, and cannot be opened with a path once packaged.
- Check spelling and case, since some systems are case-sensitive.
- The exception message names the missing path; if the missing part is a folder, create it before writing.

## Related questions

- [How do you read a file from the classpath in Java?](https://bugsee.com/answers/java/java-read-file-from-classpath/)
- [How do you read a whole file into memory with Files.readAllBytes in Java?](https://bugsee.com/answers/java/files-readallbytes/)
