您可以使用:
String os = System.getProperty("os.name");确定应用运行的操作系统,并从那里决定要做什么。像这样:
if (os.startsWith("Windows")) { // includes all Windows versions} else if (os.startsWith("Mac")) { // includes all Mac OS versions} else { // all others}我建议查找所有不同的值
os.name可能必须能够处理尽可能多的值。您可能想对这些值使用枚举,而不是
startsWith像我一样进行检查。这是您可能要考虑的值列表(尽管不是很新)。



