User:Higgs1/Minecraft App Dir

For more information see the .minecraft page.

Java
The following code is 100% compatible. As in, this is exactly how the official minecraft client does it.

import java.io.File;

static final File getMinecraftWorkingDir { String home = System.getProperty("user.home", "."); String os = System.getProperty("os.name").toLowerCase; if (os.contains("solaris") || os.contains("sunos") 	   || os.contains("linux") || os.contains("unix")) return new File(home, ".minecraft"); else if (os.contains("win")) { String appdata = System.getenv("APPDATA"); return new File(appdata != null ? appdata : home, ".minecraft"); } else if (os.contains("mac")) return new File(home, "Library/Application Support/minecraft"); return new File(home, "minecraft"); }

Alternate Version
This is mostly a code golf version. This will emulate the official minecraft client exactly, unless the user is on a posix machine and has set the "APPDATA" environment variable to a directory other than their home.

static final File getMinecraftWorkingDir { String str = (str = System.getenv("APPDATA")) == null ? System .getProperty("user.home", ".") : str; return new File(str, 	   (str = System.getProperty("os.name").toLowerCase).contains("win") 	        || str.contains("solaris") || str.contains("sunos") 	        || str.contains("linux") || str.contains("unix") ? ".minecraft" 	        : str.contains("mac") ? "Library/Application Support/minecraft" 	            : "minecraft"); }