有没有办法列出使用java连接的所有虚拟磁盘?我尝试过使用ProcessBuilder打开diskpart并运行命令,然后使用inputstreamreader,将行保存到数组中,以便稍后提取vhd名称。但在运行diskpart命令后,我的程序冻结了。
try {
commands.add("cmd.exe");
commands.add("start");
commands.add("diskpart");
commands.add("list vdisk");
ProcessBuilder builder = new ProcessBuilder(commands);
Process p = builder.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
暂无答案!
目前还没有任何答案,快来回答吧!