简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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