开发者

Refer a Document from a desktop application in java

I have an application which consist of menu's.In the help menu i have tutorial menuit开发者_开发百科em.What i want to do is when i click the menuitem "tutorial" a document in the application directory need to be opened.Can i acheive this?


It depends on the document. You could give the Desktop class a try. From the docs: "The Desktop class allows a Java application to launch associated applications registered on the native desktop to handle a URI or a file.". Note that you need at least java 6 for this.

If that doesn't work, you could also use one of the various exec(...) methods from the Runtime class. But it has quite a bit of pitfalls, this document describes them: When Runtime.exec() won't.


You can use java.awt.Desktop.getDesktop().open(file) method.

See Desktop API and Using the Desktop API in Java SE 6.


You should use the Desktop class from the Java standard Library to let the OS launch the proper application to view the document. Call the open method to view the document.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜