[英]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.name
和user.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.