[英]Getting Number of Drives in Java
我有一個很簡單的問題。
如何找到Java中與系統相連的驅動器的數量?
另外,如何確定這些硬盤是HDD,SSD還是USB?
盡管您可以從驅動器的名稱中猜出,但是沒有一種獨立於系統的方法來區分HDD和SDD。 最好的辦法是使用FileSystemView:
File[] paths;
FileSystemView fsv = FileSystemView.getFileSystemView();
// returns pathnames for files and directory
paths = File.listRoots();
// for each pathname in pathname array
for (File path : paths) {
// prints file and directory paths
System.out.println( "Drive Name: " + path );
System.out.println( "Description: " + fsv.getSystemTypeDescription(path) );
System.out.println( "Type: " + fsv.getSystemTypeDescription( path ) );
System.out.println( "Is Drive? " + fsv.isDrive( path ) );
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.