且构网

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

如何在Linux,Windows和Mac上使用Java + JNI检索硬盘的唯一ID

更新时间:2022-05-20 07:53:06

您可以使用Java + JNA( https ://github.com/twall/jna/),但随后您必须弄清楚如何通过使用要支持的每个平台上的本机库来收集信息.

You could use Java+JNA (https://github.com/twall/jna/), but then you'd have to figure out how to gather that information by using native libraries on each of the platforms you'd like to support.

好处是您不必为每个平台编译任何C/C ++代码.如果您决定使用该选项,则其他人可能会告诉您如何使用C/C ++代码/库找出不同平台上的硬盘ID.

The benefit is that you wouldn't have to compile any C/C++ code for each of the platforms. If you decide to go with that option someone else might be able to tell you how to figure out the harddisk IDs on the different platforms using C/C++ code/libraries.

AFAIK,在Linux上,您需要从/proc或/sys中读取某些内容,在Windows上,我将仔细研究MSDN,看看您会发现在Visual Studio(C ++)中可用的内容,对于Mac,则需要其他人填写如果正确执行,可能也应该支持Solaris/BSD.实际上,对于目前大多数与POSIX兼容的操作系统,我认为您应该能够做到一定程度的统一.

AFAIK, on Linux you need to read something from /proc or /sys, on Windows I would look through MSDN and see what you could find that is usable in Visual Studio (C++) and for Mac someone else would have to fill in. Solaris/BSD should probably be supported too if you do it right. In fact, for most of the POSIX-compatible OSes out there I think you should be able to do it somewhat uniformly.