Advertisement

java通过检测当前操作系统类型以实现特定功能

阅读量:

一、获取当前操作系统类型:System.getProperty("os.name")

各类操作系统所采用的执行指令存在差异:

在Windows系统中,需运行的指令为:license_windows.exe(位于当前文件夹内)

于Linux系统中,应执行的命令为:./lib/license_linux(需在特定路径下操作)

复制代码
     // 所执行的命令

    
     String cmds = "";
    
     // 获取操作系统的输出结果
    
     String os = System.getProperty("os.name");
    
     if (os != null && os.toLowerCase().startsWith("windows")) {
    
         // Windows操作系统
    
         // 获取文件相对地址
    
         File f = new File("license_windows.exe");
    
         cmds = f.getAbsolutePath();
    
     } else if (os != null && os.toLowerCase().startsWith("linux")) {

全部评论 (0)

还没有任何评论哟~