简体   繁体   English

在Java中访问NAS的最佳方法:使用外部Linux命令“ mount”进行装载

[英]Best way to accees NAS in java: Mount using external Linux command “mount”

I need to store files on a network drive (MyBook Live). 我需要将文件存储在网络驱动器(MyBook Live)上。 At the moment i'm doing this: 目前,我正在这样做:

String cmd = "mount //192.167.0.3/Public/Folder /media/Folder -o user=test,password=test"; 
Runtime run = Runtime.getRuntime() ; 
Process pr = run.exec(cmd); 
pr.waitFor();

Is there a better way to do it? 有更好的方法吗?

Did the same thing - executing a command to do the mount - for a project I was working on last fall. 对于去年秋天我正在从事的项目,执行了相同的操作-执行命令进行挂载。 There are no Java API to do this directly (or any better way as far as I know). 没有Java API可以直接(或据我所知更好的方法)直接执行此操作。 It worked properly. 它工作正常。

I agree with Bailey S recommendation of an fstab entry - did the same thing. 我同意Bailey S对fstab条目的建议-做了同样的事情。

You might want to read on the pitfalls of using Runtime.exec() and Process.waitFor() ( http://www.javaworld.com/jw-12-2000/jw-1229-traps.html?page=2 ). 您可能想阅读使用Runtime.exec()和Process.waitFor()的陷阱( http://www.javaworld.com/jw-12-2000/jw-1229-traps.html?page=2 ) 。 I prefer using Apache Commons Exec ( http://commons.apache.org/proper/commons-exec/ ) for executing OS commands. 我更喜欢使用Apache Commons Exec( http://commons.apache.org/proper/commons-exec/ )执行OS命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM