JavaDemo——读取硬盘物理序列号

通过调用wmic命令获取硬盘序列号,wmic命令很强大。

Demo:

/**
 * 2019年3月13日下午3:48:22
 */
package testReadDiskInfo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * @author XWF
 *
 */
public class ReadDiskInfo {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Process process =Runtime.getRuntime().exec(new  String[]{"wmic","diskdrive","get","Index,InterfaceType,SerialNumber"});
		process.getOutputStream().close();
		Scanner sc=new Scanner(process.getInputStream());
		String Index = sc.next();
		String InterfaceType = sc.next();
		String SerialNumber = sc.next();
		List> diskList = new ArrayList<>();
		while(sc.hasNext()) {
			Map disk = new HashMap<>();
			String index = sc.next();
			disk.put(Index, index);
			String interfacetype = sc.next();
			disk.put(InterfaceType,interfacetype);
			String serial = sc.next();
			disk.put(SerialNumber, serial);
			diskList.add(disk);
		}
		System.out.println(diskList);
	}

}

结果:

 

参考:

https://blog.csdn.net/sinat_35645479/article/details/83024969

https://www.cnblogs.com/archoncap/p/5400769.html

你可能感兴趣的:(JavaDemos)