Sunday

Liệt kê ổ đĩa hệ thống trong Java

Để liệt kê các ổ đĩa hệ thống (partition) trong Java ta dùng phương thức tĩnh listRoots() của lớp File.

File[] roots = File.listRoots();

for (int index = 0; index < roots.length; index++) 
{ 
     //Print out each drive/partition  
     System.out.println(roots[index].toString());  
}