PowerShell から複数のディスク ボリュームを取得するために、Java プロセスを介してコマンドを実行します。出力は次のようになります。

次に、各ディスクのインスタンスを保存して、SQL データベースに挿入できるようにします。
これが私がこれまでのところです:
public class Disk {
private String Letter;
private String Label;
private String Type;
private String Health;
private String Op;
private String Size;
private String Remaining;
public Disk(String letter, String label, String type, String health, String op, String size, String remaining) {
Letter = letter;
Label = label;
Type = type;
Health = health;
Op = op;
Size = size;
Remaining = remaining;
}
private List<Disk> diskTable = new ArrayList<Disk>();
public void getDiskInfo() {
//call the powershell process
ProcessBuilder pb = new ProcessBuilder();
pb.command("powershell.exe", "/c", "Get-Volume | fl DriveLetter, FileSystemLabel, FileSystemType, HealthStatus, OperationalStatus, Size, SizeRemaining");
try {
//read in the output from the powershell process
Process Diskprocess = pb.start();
BufferedReader Diskreader =
new BufferedReader(new InputStreamReader(Diskprocess.getInputStream()));
String line;
while ((line = Diskreader.readLine()) != null) {
//split the key and the value up as I won't need to store the key.
final String[] pieces = line.split(":", 2);
if (pieces.length > 1) {
String key = pieces[0];
String value = pieces[1];
//line below is just to check format of output
System.out.println(line);
//store each value into a disk instance
//add each value into the list of disks
}
}
} catch (Exception e) {
e.printStackTrace();
e.getCause();
}
}
//some other method here about adding into an SQL database
}
ディスクが 1 つしかない場合は、それぞれの値をデータベースに入力するだけで問題ありませんが、理論的には、1 台のコンピューターに多数のボリュームが存在する可能性があります。
現時点では、SQL の部分についてはあまり心配していません。ディスクの配列があれば、配列のインデックスに基づいて各ディスクをデータベースに挿入するだけでよいと思います。