如何在 Java 中挂载 Windows 驱动器?
我们正在使用一些通过字母(例如 f:\)访问共享驱动器的遗留代码。 使用 UNC 表示法不是一种选择。 我们的 Java 包装应用程序将作为服务运行,作为第一步,我想在代码中显式映射驱动器。 有人这样做过吗?
We are working with some legacy code that accesses a shared drive by the letter (f:\ for example). Using the UNC notation is not an option. Our Java wrapper app will run as a service, and as the first step, I would like to map the drive explicitly in the code. Has anyone done this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
考虑执行映射网络驱动器的 DOS 命令,如以下代码所示:
请参阅 net use 命令的详细信息:
Consider executing the DOS command that maps a network drive as in the following code:
See details on net use command:
您可以使用 JCIFS
http://jcifs.samba.org/src /docs/api/jcifs/smb/SmbFile.html
或者如果您想要更高级别的 API 并支持其他协议(如 FTP、Zip 等):
http://commons.apache.org/vfs/filesystems.html
两个选项都是纯 Java 和跨平台的。
You can use JCIFS
http://jcifs.samba.org/src/docs/api/jcifs/smb/SmbFile.html
or if you want higher level API and support for other protocols like FTP, Zip and others:
http://commons.apache.org/vfs/filesystems.html
Both options are pure Java and cross platform.
我认为最简单的方法是使用 Runtime.getRuntime().exec() 方法并调用“net use”命令。
例如:
I think the easiest way is to use the Runtime.getRuntime().exec() method and call the "net use" command.
For example: