首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从客户端程序中获取操作系统名称?

如何从客户端程序中获取操作系统名称?
EN

Stack Overflow用户
提问于 2019-07-05 13:46:13
回答 1查看 157关注 0票数 0

程序的某些部分会受到操作系统类型的影响。因此,我尝试按os名称进行分支,如下所示。当我在本地运行它时,它可以工作。但上传到服务器后,我把它作为客户端程序运行,似乎无法获取操作系统名称。请告诉我如何从客户端程序中获取操作系统名称。谢谢。

代码语言:javascript
复制
public void getOSName() {   
   String osName = System.getProperty("os.name")
   if(!osName.trim().toUpperCase().equals("WINDOWS 10")){
   run();        
   }else{
   }
}
EN

回答 1

Stack Overflow用户

发布于 2019-07-08 16:14:08

在util类下面签出操作系统验证。

使用系统属性的

:由于此issue,此方法可能会失败。请参阅Java's “os.name” for Windows 10?

代码语言:javascript
复制
/**
 * The Class OSValidator.
 */
public final class OSValidator {

    /** The Constant OS. */
    public static final String OS = System.getProperty("os.name").toLowerCase();

    /**
     * Checks if is windows 7.
     *
     * @return true, if is windows 7
     */
    public static final boolean isWindows7() {
        return (OS.indexOf("windows 7") >= 0);
    }

    /**
     * Checks if is windows 10.
     *
     * @return true, if is windows 10
     */
    public static final boolean isWindows10() {
        return (OS.indexOf("windows 10") >= 0);
    }

    /**
     * Checks if is mac.
     *
     * @return true, if is mac
     */
    public static final boolean isMac() {
        return (OS.indexOf("mac") >= 0);
    }
}

使用SystemUtils的

- Apache Commons Lang

代码语言:javascript
复制
public String getOperatingSystemSystemUtils() {
    String os = SystemUtils.OS_NAME;
    // System.out.println("Using SystemUtils: " + os);
    return os;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56897149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档