Get partition and volume information

夙愿已清 提交于 2019-12-12 09:58:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!