I have a Java Application which uses xml file to load settings during s start time. I want to run this application on Linux, Windows and many other Operating systems.
The problem is the file path which is different in every OS. The only solution that I think on is to get the OS platform type and based on it to load the appropriate config file:
/**
 * helper class to check the operating system this Java VM runs in
 */
public static final class OsCheck {
  /**
   * types of Operating Systems
   */
  public enum OSType {
    Windows, MacOS, Linux, Other
  };
  protected static OSType detectedOS;
  /**
   * detected the operating system from the os.name System property and cache
   * the result
   * 
   * @returns - the operating system detected
   */
  public static OSType getOperatingSystemType() {
    if (detectedOS == null) {
      String OS = System.getProperty("os.name", "generic").toLowerCase();
      if (OS.indexOf("win") >= 0) {
        detectedOS = OSType.Windows;
      } else if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
        detectedOS = OSType.MacOS;
      } else if (OS.indexOf("nux") >= 0) {
        detectedOS = OSType.Linux;
      } else {
        detectedOS = OSType.Other;
      }
    }
    return detectedOS;
  }
}
Is there any better approach?
 
    