I’ve been trying to get my options menu working for the past few hours now and it’s just about finished; my only problem now is that the program, for some ridiculous reason, thinks that a file, that exists, doesn’t exist.
Here is where I’m loading the file:
public String[] loadFile(String filePath)
{
int lineCounter = 0;
ArrayList<String> lines = new ArrayList<>();
try
{
final URL url = new URL(getClass().getProtectionDomain().getCodeSource().getLocation().toString()+filePath);
System.out.println(url);
final BufferedReader bufferedReader = new BufferedReader(new FileReader(url.toString()));
String line = null;
while((line = bufferedReader.readLine()) != null)
{
lines.add(line);
lineCounter++;
}
bufferedReader.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return lines.toArray(new String[lines.size()]);
}
Here is the error message:
java.io.FileNotFoundException: file:\C:\Users\Tyler\Java%20Projects\Text%20Based%20Game\build\classes\Options.txt (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at java.io.FileReader.<init>(FileReader.java:58)
at Core.ResourceHandler.loadFile(ResourceHandler.java:69)
at Screens.ScreenMainMenu.<init>(ScreenMainMenu.java:25)
at Core.GameCanvas.<init>(GameCanvas.java:37)
at Core.GameFrame.<init>(GameFrame.java:21)
at Core.GameFrame.main(GameFrame.java:46)
I’ve triple checked to make sure that the file does exist and that it has all of the needed information within, the information is a single integer on line 1 that say which music track to use. I’ve also tried a few different ways to point the program to the file but they all have the same result.
The way that I’m attempting to get it to work is that, no matter where the .jar file is, there will always be an Options.txt in the same folder that will contain all of the options for the program; this will be read from when the program starts up and then written to if anything is changed in the menu. Everything looks like it should work but the program is just keeps throwing a file not found exception…