Java: Get Application Data folder for different platforms

The following snippet returns the application data folder, like c:\Dokumente und Einstellungen\username\ApplicationData on Windows, where you can store settings or other stuff for your application. It will also return the correct path for OSX and Linux:

 * Returns the application data path, path is returned with ending /
 * @return
public static String getAppData() {
 String path = "";
  String OS = System.getProperty("").toUpperCase();
  if (OS.contains("WIN"))
   path = System.getenv("APPDATA");
  else if (OS.contains("MAC"))
   path = System.getProperty("user.home") + "/Library/";
  else if (OS.contains("NUX"))
   path = System.getProperty("user.home");
  else path =  System.getProperty("user.dir");

  path = addSeparator(path);

  return path;


comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum