I have a game engine based on LWJGL, and to run it I need to place the required native libraries onto the user's computer. On Windows, I do so by finding the Application Data directory via:
System.getenv("APPDATA");
and everything works easily and nicely. I create a File object, call mkDir if necessary, and write the files if they are not already on the machine.
(Note: the created directory should not be a temporary file, as I would like to save the extracted files for future runs. Additionally, creating this directory gives a simple and easy-to-use folder for saved games and other such data.)
However, I'd like to do something similar if the computer is Macintosh or Linux, but I'm not as familiar with how to do so with those two systems, and I'm not really in a good testing position. My current method to find the target directory is this:
private static String defaultDirectory()
{
String OS = System.getProperty("os.name").toUpperCase();
if (OS.contains("WIN"))
return System.getenv("APPDATA");
else if (OS.contains("MAC"))
return System.getProperty("user.home") + "/Library/Application "
+ "Support";
else if (OS.contains("NUX"))
return System.getProperty("user.home");
return System.getProperty("user.dir");
}
So, is this the right way to do this? I'm trying to reach the Application Support on Mac (I've learned this is the equivalent of the AppData folder on windows) and I'm trying to use a similar folder on Linux, but I'm not sure if "user.home" finds the correct one.
this should work. just one thing: on linux it is preferred to keep settings in a hidden folder in user directory. So for linux, either put your folder under $HOME/.config, or start the name with the .
to make it hidden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With