Reputation: 306
So I need the client to store the server address etc... locally and also have it encrypted but where should the file be kept as I have tried putting it in the Program Files folder but I am getting an error. It works fine on mac but not windows.
/**
* Gets the path to the configuration file
* dependent on the operating system.
*
* @return File Path {@code File}
*/
public File getOSConfigurationPath () {
File file;
if (System.getProperty("os.name").startsWith("Windows")) {
file = new File (System.getProperty("user.home") + "/Program Files/AutoSales/Configuration.txt");
} else {
file = new File (System.getProperty("user.home") + "/Library/Application Support/AutoSales/Configuration.txt");
}
return file;
}
The file where ^^^^ is returned to uses it like this.
} else {
file.createNewFile();
System.out.println("New Config File Created");
}
For some reason the Windows save path give this error.
Any advice would be greatly appreciated. Thanks.
Upvotes: 2
Views: 839
Reputation: 287
Does this exception occur on the line where you get the Windows file location or at some point later? Usually such exception means that your code is being executed more than once and you get recursive repeating calls which eventually leads to stack overflow.
The first thing to do here is to debug the code and see when exactly this exception happens. Once you isolate the code, you will be able to fix the issue.
Another note - are you using SwingUtilities.invokeLater(Runnable) when you invoke UI related operations? This is a must when you deal with Java Swing UI.
http://www.javamex.com/tutorials/threads/invokelater.shtml
Upvotes: 1