我目前包含以下无法编译的代码。else if语句报告';' 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;发布于 2012-02-16 19:48:03
如果你使用user.name和user.home会更好。您也可以使用file.separator获取分隔符。Check this out。这些属性将真正帮助您在不检查操作系统的情况下更干净地完成此操作。
还有一个问题是,你需要改用else if,而不是elseif……
发布于 2012-02-16 19:48:37
如果在java中不存在,则返回。如果为,则必须使用else:
if (a) {
// code
} else if (b) {
// code
}发布于 2012-02-16 19:44:23
java中没有elseif关键字。你应该说else if (注意空格)
https://stackoverflow.com/questions/9310660
复制相似问题