开发者

How can I mount network drive in Mac OS X on Java?

开发者 https://www.devze.com 2022-12-21 11:36 出处:网络
I am writing a programme on JBuider 2005 on Windows XP platform for Mac OS X开发者_运维知识库. Programme must launch on Mac OS X and programme turnes(directs) to share folders on other computer(Window

I am writing a programme on JBuider 2005 on Windows XP platform for Mac OS X开发者_运维知识库. Programme must launch on Mac OS X and programme turnes(directs) to share folders on other computer(Windows XP) in network. It is necessary that then we launch nprogramme on Mac OS X this programme automatically mount these share folders under Mac OS X. Then programme turnes to files on share folder and path in program will be "/Volumes/Share folder/File". How can i make it? Help, if anyone knows how to do it.


If it is a afp-volume that you have to mount, the code looks like this:

   Process p1 = Runtime.getRuntime().exec("/bin/mkdir /Volumes/<mountName>");
   p1.waitFor();
   Process p2 = Runtime.getRuntime().exec(new String[] {"/sbin/mount_afp","-i","afp://<user>:<passwd>@url.of.serv.er/mountPath/","/Volumes/<mountName>/"});
   p2.waitFor();

If it is a smb-mount, then the code looks like this:

    Process p3 = Runtime.getRuntime().exec("/bin/mkdir /Volumes/<mountName>");
    p3.waitFor();
    Process p4 = Runtime.getRuntime().exec(new String[] {"/sbin/mount","-t","smbfs","//<user>:<passwd>@url.of.serv.er/mountPath/","/Volumes/<mountName>/"});
    p4.waitFor();


Perhaps run a bit of AppleScript which has Finder mount the shared folder. This article describes running AppleScript from a Java program.

Or run a shell script:

mount -t smbfs //user@server/share folder
0

精彩评论

暂无评论...
验证码 换一张
取 消