![](/img/trans.png)
[英]How can I tell a Linux Distro to apt-get install LibVLC if it doesn't have it from a running Java Program?
[英]how can I tell in java if the program is running on a windows or linux machine?
有沒有辦法用Java判斷程序是否在Windows或Linux計算機上運行? 我有一個要在兩者上運行的.jar文件。
您可以使用以下方式獲取操作系統類型
System.getProperty("os.name")
干得好,
如何以編程方式確定Java的操作系統?
VonC的答案
public static final class OsUtils
{
private static String OS = null;
public static String getOsName()
{
if(OS == null) { OS = System.getProperty("os.name"); }
return OS;
}
public static boolean isWindows()
{
return getOsName().startsWith("Windows");
}
public static boolean isUnix() // and so on
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.