如何在Java编程语言中安装和卸载硬盘驱动器(独立于平台,因此不使用Runtime执行硬编码命令)?
The answer is "Yes And No". You could not mount or unmount devices in java because each OS has their own methods to do this. BUT... you can provide java api that use adapter pattern for native interface. You should do some things:
It is not pure java, but is good solution I think. Client code will use java.
由于没有办法可移植(或者甚至使用相同的语义),因此没有内置的Java方法。
"Platform independent" doesn't mean you are not allowed to use external processes. You can check the OS your app is runnning on. See System.getProperty("os.name");
Depending on the result of that method, invoke the correct process.
Think about it: Java is supposed to work on platforms where no hard drives exist, so how could there be a platform independent way of doing this?
Besides, even if you restricted it to platforms where hard disks are available, how is Java supposed to abstract away the different approaches to RAIDs / partitions / slices etc?
Why do you want/need to do this?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.