Best way to use NAS in java: mount using an external Linux mount command

I need to store files on a network drive (MyBook Live). At the moment I am 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 this?

+4
source share
1 answer

The same thing — running the mount command — for a project I worked on last fall. There is no Java API to do this directly (or as best as possible, as far as I know). It worked correctly.

I agree with Bailey S's recommendation on fstab - did the same.

You might want to read about errors using Runtime.exec () and Process.waitFor () ( http://www.javaworld.com/jw-12-2000/jw-1229-traps.html?page=2 ). I prefer to use Apache Commons Exec ( http://commons.apache.org/proper/commons-exec/ ) to execute OS commands.

+2
source

Source: https://habr.com/ru/post/1480221/


All Articles