Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Java Multi Platform Save Directory

For mac use ~/Library/Application Support
... Not sure what people usually use for most distros of Linux, but somewhere in the home folder works.

ninja: I don't think you can use backslashes for anything other than dos. File.separator or just "/" works.
(Jun 25, 2015 07:42 PM)JershDervis Wrote:  I know the Minecraft Launcher uses the following method:
Code
public static final String APPLICATION_NAME = "minecraft";

    public enum OS
    {
      WINDOWS,  MACOS,  SOLARIS,  LINUX,  UNKNOWN;
    }

    public static OS getPlatform()
    {
      String osName = System.getProperty("os.name").toLowerCase();
      if (osName.contains("win")) {
      return OS.WINDOWS;
      }
      if (osName.contains("mac")) {
      return OS.MACOS;
      }
      if (osName.contains("linux")) {
      return OS.LINUX;
      }
      if (osName.contains("unix")) {
      return OS.LINUX;
      }
      return OS.UNKNOWN;
    }

    public static File getWorkingDirectory()
    {
      String userHome = System.getProperty("user.home", ".");
      File workingDirectory;
      switch (getPlatform().ordinal())
      {
      case 1:
      case 2:
      workingDirectory = new File(userHome, "." + APPLICATION_NAME + "/");
      break;
      case 3:
      String applicationData = System.getenv("APPDATA");
      String folder = applicationData != null ? applicationData : userHome;

      workingDirectory = new File(folder, "." + APPLICATION_NAME + "/");
      break;
      case 4:
      workingDirectory = new File(userHome, "Library/Application Support/" + APPLICATION_NAME);
      break;
      default:
      workingDirectory = new File(userHome, APPLICATION_NAME + "/");
      }
      return workingDirectory;
    }

That's decompiled from the launcher, right? I'm just assuming that because enum switches use ordinal() after being compiled and no one writes enum switches with ordinal


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by -DarkByDesign-May 14, 2020 12:13 PM 0 126 May 14, 2020 12:13 PM
Last Post: -DarkByDesign-
[Java] by DessieOct 4, 2016 09:56 AM 5 169 Oct 4, 2016 09:56 AM
Last Post: Dessie
[C#] by gotoelAug 15, 2016 01:35 PM 15 1,066 Aug 15, 2016 01:35 PM
Last Post: Ninja