集册 Java实例教程 从用户代理获取操作系统

从用户代理获取操作系统

欢马劈雪     最近更新时间:2020-01-02 10:19:05

511
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从用户代理获取操作系统
/**
N o w  J a v a  .   c o m 提供 
**/


//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        String userAgent = "nowjava.com";

        System.out.println(getOs(userAgent));

    }


    @Deprecated

    public static String getOs(String userAgent) {

        String os = "";

        if (userAgent.indexOf("Windows NT 6.3") != -1) {

            os = "Windows 8.1";

        } else if (userAgent.indexOf("Windows NT 6.2") != -1) {

            os = "Windows 8";

        } else if (userAgent.indexOf("Windows NT 6.1") != -1) {

            os = "Windows 7";

        } else if (userAgent.indexOf("Windows NT 6.0") != -1) {

            os = "Windows Vista";// 来 自 N o w  J a v a  . c o m

        } else if (userAgent.indexOf("Windows NT 5.2") != -1) {

            os = "Windows Server 2003";

        } else if (userAgent.indexOf("Windows XP") != -1) {

            os = "Windows XP";

        } else if (userAgent.indexOf("Windows NT 5.1") != -1) {

            os = "Windows XP";

        } else if (userAgent.indexOf("Windows 9x 4.90") != -1) {

            os = "Windows ME";

        } else if (userAgent.indexOf("Windows ME") != -1) {

            os = "Windows ME";

        } else if (userAgent.indexOf("Windows NT 5.0") != -1) {

            os = "Windows 2000";

        } else if (userAgent.indexOf("Windows 2000") != -1) {

            os = "Windows 2000";

        } else if (userAgent.indexOf("Windows 98") != -1) {

            os = "Windows 98";

        } else if (userAgent.indexOf("Windows NT 4.0") != -1) {

            os = "Windows NT";

        } else if (userAgent.indexOf("Windows 95") != -1) {

            os = "Windows 95";

        } else if (userAgent.indexOf("Mac") != -1) {

            os = "Mac OS";

        } else 
展开阅读全文