The file is missing
Even though the path is there, the actual file might not be in the correct place.
The path is wrong
The program might be looking in a different folder than you expect. It might be using a relative path (like just myfile.txt
), which depends on where the app runs from.
It's a file from resources
, but used like a normal file
If the file is inside src/main/resources
, you can’t use new File("myfile.txt")
directly. You need to load it like this:
InputStream input = getClass().getResourceAsStream("/myfile.txt");