I've been trying for hours to get it to read a file that is in the same directory as the executable JAR:
My code is:
Object obj = parser.parse(new FileReader("configuracion.json"));
But I already tried with
- "./config.json"
- ".\\config.json"
- I tried putting it in a "resources" folder at the root of the project and doing what
...getResource("configuracion.json").getPath()
but it didn't work when exporting either, only during debugging in Eclipse.
When I run it in Eclipse (the configuration.json is in the root of the project) it works, but when I export it to an it Runnable JAR
throws FileNotFoundException
.
If anyone could lend a hand I would greatly appreciate it.
To avoid this type of situation, I have a function that searches the directory and checks if the path to return is correct. Edited based on comments
In your specific code, it would be to add this in the following way and having the file next to the jar
Take a look and see if it works for you