栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何用Java检查Windows版本?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何用Java检查Windows版本?

您始终可以使用Java调用Windows命令“ systeminfo”,然后解析结果,我似乎找不到在Java中原生执行此操作的方法。

 import java.io.*;   public class GetWindowsEditionTest   {      public static void main(String[] args)      {         Runtime rt;          Process pr;          BufferedReader in;         String line = "";         String sysInfo = "";         String edition = "";         String fullOSName = "";         final String   SEARCH_TERM = "OS Name:";         final String[] EDITIONS = { "Basic", "Home",     "Professional", "Enterprise" };         try         { rt = Runtime.getRuntime(); pr = rt.exec("SYSTEMINFO"); in = new BufferedReader(new InputStreamReader(pr.getInputStream())); //add all the lines into a variable while((line=in.readLine()) != null) {    if(line.contains(SEARCH_TERM)) //found the OS you are using    {     //extract the full os name       fullOSName = line.substring(line.lastIndexOf(SEARCH_TERM)        + SEARCH_TERM.length(), line.length()-1);       break;    }  } //extract the edition of windows you are using for(String s : EDITIONS) {    if(fullOSName.trim().contains(s))    {       edition = s;    } } System.out.println("The edition of Windows you are using is "          + edition);         } catch(IOException ioe)       {       System.err.println(ioe.getMessage()); }      }   }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/463684.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号