获取分区和卷信息 [英] Get partition and volume information

查看:120
本文介绍了获取分区和卷信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法只使用Java库获取磁盘分区和卷信息?我还需要删除文件信息。磁盘格式化为FAT-16并具有标准MBR。

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.

我需要以下信息:

a )分区信息 - 显示磁盘上的分区数,并为每个
分区显示起始扇区,分区大小和文件系统类型。

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)卷信息 - 仅对于第一个分区,显示每个
群集的扇区数,FAT区域的大小,根目录的大小以及集群#2的扇区地址

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)已删除的文件信息 - 对于卷根目录下的第一个已删除文件,
显示该文件的名称和大小,以及第一个集群的编号。显示该文件内容的
前16个字符(假设它是一个简单的文本文件)。

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).

推荐答案

如果您需要在Java中获取文件系统详细信息试试这个:

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());
        }
    }
}

引自这个答案


使用JNA,你可以调用Win32 Kernel32的GetVolumeInformation()到
检索lpFileSystemNameBuffer参数,该参数接收文件系统的
名称,例如FAT文件系统或NTFS文件
system

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

这篇关于获取分区和卷信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆