问题
Is there a way to get disk partition and volume information using Java libraries only? I also need deleted file information. Disk is formatted as a FAT-16 and has standard MBR.
I need the following information:
a) Partition information - Display the number of partitions on the disk and for each partition display the start sector, size of partition and file system type.
b) Volume information – For the first partition only, display the number of sectors per cluster, the size of the FAT area, the size of the Root Directory, and the sector address of Cluster #2.
c) Deleted file information - For the first deleted file on the volume’s root directory, display the name and size of that file, and the number of the first cluster. Display the first 16 characters of the content of that file (assume it is a simple text file).
回答1:
If you need to Getting file system details in Java try This:
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.event.*;
import java.io.File;
import javax.swing.filechooser.FileSystemView;
public class Main {
public static void main(String[] args) {
System.out.println("File system roots returned byFileSystemView.getFileSystemView():");
FileSystemView fsv = FileSystemView.getFileSystemView();
File[] roots = fsv.getRoots();
for (int i = 0; i < roots.length; i++) {
System.out.println("Root: " + roots[i]);
}
System.out.println("Home directory: " + fsv.getHomeDirectory());
System.out.println("File system roots returned by File.listRoots():");
File[] f = File.listRoots();
for (int i = 0; i < f.length; i++) {
System.out.println("Drive: " + f[i]);
System.out.println("Display name: " + fsv.getSystemDisplayName(f[i]));
System.out.println("Is drive: " + fsv.isDrive(f[i]));
System.out.println("Is floppy: " + fsv.isFloppyDrive(f[i]));
System.out.println("Readable: " + f[i].canRead());
System.out.println("Writable: " + f[i].canWrite());
System.out.println("Total space: " + f[i].getTotalSpace());
System.out.println("Usable space: " + f[i].getUsableSpace());
}
}
}
Quoted from this answer:
Using JNA, you can call Win32 Kernel32's GetVolumeInformation() to retrieve lpFileSystemNameBuffer parameter which receives the name of the file system, for example, the FAT file system or the NTFS file system
来源:https://stackoverflow.com/questions/15656139/get-partition-and-volume-information