如何使用java代码获取USB驱动器序列号或元数据 [英] How to get USB drive serial number or meta data using java code

查看:39
本文介绍了如何使用java代码获取USB驱动器序列号或元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用 Java 编写了一个桌面应用程序.我想用 Pendrive 或任何其他 USB 驱动器保护它.但是我不知道如何使用java代码读取pendrive或usb驱动器,以便限制应用程序.

I have prepared one desktop application in java. And I want to protect it by Pendrive or any other usb drive. But I dont know how to read pendrive or usb drive using java code, so that I can restrict the application.

请帮助我如何做到这一点?或者对此有何其他想法?

Plese help me how to do this? Or any other idea regarding this?

谢谢..:)

推荐答案

就像我上面那个人说的,你可以列出你的 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!

这篇关于如何使用java代码获取USB驱动器序列号或元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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