Hello Guest

appdata?

  • 3 Replies
  • 3841 Views
*

Offline dangerdoc

  • **
  • 75
  • Thats right... Nikola Tesla
appdata?
« 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.

Re: appdata?
« Reply #1 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.

Code: [Select]
// 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;
}

*

Offline dangerdoc

  • **
  • 75
  • Thats right... Nikola Tesla
Re: appdata?
« Reply #2 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.

Re: appdata?
« Reply #3 on: September 21, 2012, 12:25:35 »
You mean URL.openStream(), right? That should be more than sufficient.