I am using ObjectOutputStream and ObjectInputStream to read and write data that needs to be stored in between program runs. My question is if there is a proper place to create these files. At the moment I use the following code to find the user's Documents folder.
String myDocuments = null;
try {
Process p = Runtime.getRuntime()
.exec("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v personal");
p.waitFor();
InputStream in = p.getInputStream();
byte[] b = new byte[in.available()];
if (in.read(b) == 0) myDocuments = JOptionPane.showInputDialog(this,
"A fatal error has occurred. \n Please provide your documents folder.");
else {
myDocuments = new String(b);
myDocuments = myDocuments.split("\\s\\s+")[4];
}
in.close();
Log.logLine(myDocuments);
} catch (Throwable t) {
t.printStackTrace();
}
Is this okay as a practice, and if not where should I be storing this information? Also is there a way to do this while still allowing for the application to run a different OS as I am aware that the current method only works with Windows OS.