How can I make OS X recognize drive letters?

后端 未结 7 1684
长情又很酷
长情又很酷 2021-01-20 23:11

I know. Heresy. But I\'m in a bind. I have a lot of config files that use absolute path names, which creates an incompatibility between OS X and Windows. If I can get OS X (

7条回答
  •  盖世英雄少女心
    2021-01-20 23:47

    If you are not willing to change your config file per OS, what are they for in first place?

    Every installation should have its own set of config files and use it accordingly.

    But if you insist.. you just have to detect the OS version and if is not Windows, ignore the letter:

    Something along the lines:

    boolean isWindows = System.getProperty("os.name").toLowerCase()
            .contains("windows");
    
    String folder = "S:";
    if (isWindows && folder.matches("\\w:")) {
        folder = "/";
    } else if (isWindows && folder.matches("\\w:.+")) {
        folder = folder.substring(2);// ignoring the first two letters S:
    }
    

    You get the idea

提交回复
热议问题