且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用java代码获取USB驱动器序列号或元数据

更新时间:2022-01-07 01:33:32

就像我上面那个人说的,你可以列出你的 USB 目录的根目录.列出根目录后,您可以手动找到 USB 驱动器,然后使用 FileOutputStreams 将 USB 驱动器中的 File 对象写入 File,然后稍后将该 File 对象与您的驱动器进行比较.或者您可以在 USB 驱动器中创建一个唯一的文件名并使用

Like the person above me said, you can list the roots of your USB directory. After you list the roots, you can find the USB drive manually then write the File object from your USB drive to a File using FileOutputStreams and then just compare that File object later to your drive. Or you can make a unique file name in your USB drive and use

File[] roots = File.listRoots();for(int i = 0; i < roots.length; i++){
File[] filesInRoot = File.listRoots()[i].listFiles();
for(int j = 0; j < filesInRoot.length; j++){
    if(filesInRoot[j].getName().equals(yourUniqueFileName))
        executeYourCode();

    }
}

有什么问题可以问!这是一个非常有趣的问题,所以如果您需要代码方面的帮助,请与我联系!

Ask any questions if you need it! This is a very interesting problem so if you need help with the code, chat me!