从此处更改我的字符串后:
String osver = System.getProperty("os.name");
if (osver.contains("Mac")){
String app = wd + "/relap5.x\"";
} else if (osver.contains("Windows")){
String app = "relap5.exe";
} else if (osver.contains("linux")) {
String app = "/relap5.x";
}
对此:
String[] osver = {System.getProperty("os.name")};
if (osver.contains("Mac")){
String[] app = {wd + "/relap5.x\""};
} else if (osver.contains("Windows")){
String[] app = {"relap5.exe"};
} else if (osver.contains("linux")) {
String[] app = {"/relap5.x"};
}
我收到错误。
Cannot find symbol
symbol: method contains(String)
Location variable osver of type string[]
答案 0 :(得分:1)
你不能对数组进行包含。 你也可以这样做:
List<String> osver = Arrays.asList(System.getProperty("os.name"));
if (osver.contains("Mac")) {
String[] app = { wd + "/relap5.x\"" };
} else if (osver.contains("Windows")) {
String[] app = { "relap5.exe" };
} else if (osver.contains("linux")) {
String[] app = { "/relap5.x" };
}
答案 1 :(得分:0)
这是因为Array
不包含方法contains
。你的意思是:
String osver = System.getProperty("os.name");
String app;
if (osver.equals("Mac")){
app = "wd" + "/relap5.x\"";
} else if (osver.equals("Windows")){
app = "relap5.exe";
} else if (osver.equals("linux")) {
app = "/relap5.x";
}
System.out.println(app);
以上代码将检查是否相等,但如果要检查包含,请使用:
String osver = System.getProperty("os.name");
String app;
if (osver.contains("Mac")){
app = "wd" + "/relap5.x\"";
} else if (osver.contains("Windows")){
app = "relap5.exe";
} else if (osver.contains("linux")) {
app = "/relap5.x";
}
System.out.println(app);