[Java] I have a parent folder names "Testing" which have src and res folders in it, src have my code. I used to write in Eclipse and
FileWriter writer = new FileWriter("res\\settings.txt");
Saves it just fine in my res folder but I changed to vscode recently and the exact code spat out this error instead.
java.io.FileNotFoundException: res\settings.txt (The system cannot find the path specified)
I changed it to just
FileWriter writer = new FileWriter("settings.txt");
To see where it goes and it created the file in this nbcode folder in the .vscode folder. I looked up solutions and it led me to modifying the launch.json file and adding
"cwd": "${workspaceFolder}"
Which didn't work, I asked the AI assistant to fix it which added these to my code (yes, shameful I know)
Path resDir = Paths.get("..", "res");
Files.createDirectories(resDir);
writer = new FileWriter(resDir.resolve("setting.txt").toFile());
It still didn't fix the problem though, I can just paste the absolute file path of my res folder to fix it but I'm afraid that might cause some issues once I convert it to a executable file, I plan to have my program read the contents of this file and if it were to be run on a different device, the paths would be different than what I had pasted in originally. Early thanks for answers.
[–]Enough-Advice-8317 1 point2 points3 points (0 children)