繁体   English   中英

用于声明文件路径位置的Java跨平台操作系统检测

[英]Java Cross-Platform OS detection to declare file path location

我目前包含以下无法编译的代码。 else if语句报告' ;' expected ;' expected 我不明白为什么我不能使用else if在这种情况下?

public class FileConfiguration {

    private String checkOs() {
        String path = "";        
        if (System.getProperty("os.name").startsWith("Windows")) {
            // includes: Windows 2000,  Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP
            path = "C://Users//...";            

        }
        elseif (System.getProperty("os.name").startsWith("Mac")) {
            path = "///Users//...";
        }
        return path;        

    }

    // declare paths for file source and destination 
    String destinationPath = path;
    String sourcePath = path;

如果你使用user.nameuser.home会更好。 您还可以使用file.separator获取分隔符。 看看这个 这些属性将真正帮助您在不检查操作系统的情况下更干净地完成此操作。

再有就是还的,你需要改变使用此事else if不是elseif ...

elseif在java中不存在。 你必须使用else if

if (a) {
// code
} else if (b) {
// code
}

java中没有elseif关键字。 else if (注意空间)你应该说

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM