java获取硬盘序列号(windows系统)


代码如下:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Example1 {
    
    public static String getHdSerialInfo() {

          String line = "";
          String HdSerial = "";//定义变量 硬盘序列号
          try {
           Process proces = Runtime.getRuntime().exec("cmd /c dir c:");//获取命令行参数
           BufferedReader buffreader = new BufferedReader(new InputStreamReader(proces.getInputStream(),"gbk"));

           while ((line = buffreader.readLine()) != null) {
            if (line.indexOf("卷的序列号是 ") != -1) {  //读取参数并获取硬盘序列号

             HdSerial = line.substring(line.indexOf("卷的序列号是 ") + "卷的序列号是 ".length(), line.length());
             break;
            }
           }

          } catch (IOException e) {
           e.printStackTrace();
          }

          return HdSerial;
         }

    /**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(getHdSerialInfo());

    }

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM