appdata?

Started by dangerdoc, September 20, 2012, 19:31:47

Previous topic - Next topic

dangerdoc

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.
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

CodeBunny

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;
	}

dangerdoc

Thanks for the help codebunny! Now I can (hopefully) make an updater library, which I plan to make using simple http protocol.
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

CodeBunny

You mean URL.openStream(), right? That should be more than sufficient.