在Java上使用外部应用程序打开文件 [英] Open a file with an external application on Java
本文介绍了在Java上使用外部应用程序打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当您不知道文件与哪个应用程序相关联时,如何从Java应用程序中打开文件。另外,因为我使用的是Java,所以我更喜欢独立于平台的解决方案。
How do you open a file from a java application when you do not know which application the file is associated with. Also, because I'm using Java, I'd prefer a platform independent solution.
推荐答案
使用JDK1.6,< a href =http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html\"rel =noreferrer> java.awt.Desktop
类可能很有用。
With JDK1.6, the java.awt.Desktop
class can be useful.
public static void open(File document) throws IOException {
Desktop dt = Desktop.getDesktop();
dt.open(document);
}
这篇关于在Java上使用外部应用程序打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文