开发者

Open a PDF file on a remote machine with local app in Java?

When I run code like this in Mac os:

Runtime.getRuntime.exec("open  testFile.pdf");

the Mac OS will run Acrobat to open the l开发者_如何转开发ocal PDF file.

How can I do it, when the file is on a remote machine?

\\remoteHost\share\testFile.pdf

I try to do that like this:

Runtime.getRuntime.exec("open \\\\remoteHost\\share\\testFile.pdf");

but I failed.

Thanks!


Runtime.getRuntime().exec(String) just passes the String to the OS for it to handle it. So, if you want to run the command

open \\remoteHost\share\testFile.pdf

You have to pass it to exec(). Remember to escape the \ (replace every \ by \\)

Runtime.getRuntime().exec("open \\\\remoteHost\\share\\testFile.pdf");

Of course, the user running the program should have permissions in the remote machine. If you need to set another user, use the open program command line parameters.


I don't think it's possible to directly specify the path of an SMB share while using the open command. If you want to use open, you would have to mount that share as a local directory. See http://osxdaily.com/2009/09/24/access-and-mount-an-smb-share-via-command-line/ for an explanation.

A solution like that would be pretty fragile though. If you want a more reliable solution, I'd suggest using JCIFS (http://jcifs.samba.org/) to download the file locally and then use

Desktop.getDesktop().open(pdfFile);

to open the downloaded file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜