LWJGL Forum

Programming => General Java Game Development => Topic started by: dangerdoc on September 20, 2012, 19:31:47

Title: appdata?
Post by: dangerdoc on September 20, 2012, 19:31:47
How would I find the directory %appdata% for windows in java? And how would I access the %appdata% directory in linux? I am going to make my own library that does this, but I need to know how to find the directory.
Title: Re: appdata?
Post by: CodeBunny on September 20, 2012, 21:26:08
This is part of a personal utility library I wrote. All you need is the file path, you can write to the directories normally thereafter.


// Detects operating system.
String opSys = System.getProperty("os.name").toUpperCase();
if (opSys.contains("WIN"))
system.os = OperatingSystem.WINDOWS;
else if (opSys.contains("MAC"))
system.os = OperatingSystem.MAC;
else if (opSys.contains("NUX") || opSys.contains("NIX"))
system.os = OperatingSystem.LINUX;
else if (opSys.contains("SOL"))
system.os = OperatingSystem.SOLARIS;
else
system.os = OperatingSystem.UNKNOWN;

// Detects the user's home directory.
system.homeDir = System.getProperty("user.home");

// Detects the user's active directory.
system.workingDir = System.getProperty("user.dir");

// Detects the path to the application directory.
switch(system.os)
{
case WINDOWS:
system.applicationDir = System.getenv("APPDATA");
break;
case MAC:
system.applicationDir = System.getProperty("user.home") +
"/Library/Application Support";
break;
default:
system.applicationDir = system.homeDir;
break;
}
Title: Re: appdata?
Post by: dangerdoc on September 20, 2012, 22:38:49
Thanks for the help codebunny! Now I can (hopefully) make an updater library, which I plan to make using simple http protocol.
Title: Re: appdata?
Post by: CodeBunny on September 21, 2012, 12:25:35
You mean URL.openStream(), right? That should be more than sufficient.