0

我有一个在 Windows 机器上开发的 Java Web 应用程序,并将部署在 Unix 机器上。

两者之间存在一些不同的文件路径设置和权限详细信息(我无法更改此设置)。是否有某种方法可以通过检测操作系统或计算机名称来检测应用程序所在的机器(它只是其中之一),以便我可以使用适当的设置。

4

4 回答 4

5

计算机名称和操作系统名称是获取计算机名称使用的两个不同属性

String computername=InetAddress.getLocalHost().getHostName();
      System.out.println(computername);

并使用操作系统名称

java.lang.System.getProperty("os.name")

阿卜杜勒哈利克

于 2010-05-18T06:22:13.413 回答
3

您可以使用

java.lang.System.getProperty("os.name")

知道操作系统名称。

在https://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html获取更多信息。

于 2010-05-18T05:53:42.907 回答
2

检查这个:http ://www.roseindia.net/java/beginners/OSInformation.shtml

于 2010-05-18T05:50:07.330 回答
1

您可以使用System.getProperty("os.name")

于 2010-05-18T05:53:01.103 回答