安装和卸载硬盘驱动器 [英] Mount and unmount hard drives

查看:954
本文介绍了安装和卸载硬盘驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Java编程语言中安装和卸载硬盘驱动器(独立于平台,因此不使用运行系统执行硬编码命令)?

How can I mount and unmount hard drives (platform independent, so no using Runtime to execute a hard-coded command) in the Java Programming Language?

推荐答案

答案是是和否。您无法在java中装载或卸载设备,因为每个操作系统都有自己的方法来执行此操作。但是......您可以提供使用适配器模式进行本机接口的java api。你应该做一些事情:

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:


  • 创建支持mount / unmount命令的Java接口

  • 创建类将接口实现为本机方法

  • 使用C语言或其他语言创建此命令的本机实现。 OS的一个实现(Win,Mac,Linux)

  • 将它打包到一个jar

  • 构建小工厂,提供接口的实现并加载本机库

  • create Java interfaces that support mount/unmount commands
  • create classes that implements interfaces as native methods
  • create native implementations of this commands in C or other language. One implemantation for OS (Win, Mac, Linux)
  • pack it to one jar
  • build small factory that provide implementation of interface and load native libraries

这不是纯粹的java,但我认为这是一个很好的解决方案。客户端代码将使用java。

It is not pure java, but is good solution I think. Client code will use java.

这篇关于安装和卸载硬盘驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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