如何知道任何文件/程序与Java的哪个默认程序相关联? 4 月,1 周 Questions & Answers 157 我只是想知道如何知道与任何外部程序/文件关联的默认程序。对于ex,默认情况下,java文件是用哪个程序打开的?这一点我必须知道使用Java程序本身
# 1 楼答案 如果你想打开一个包含相关程序的文件,你其实不需要知道相关的程序,因为Java可以使用Java为你做关联。awt。桌面类 // application associated to a file extension public static void open(File document) throws IOException { Desktop dt = Desktop.getDesktop(); dt.open(document); }
# 2 楼答案 在窗口上: Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("ftype > %YOUR_DIRECTORY%\\type_program.properties"); Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream("%YOUR_DIRECTORY%\\type_program.properties"); prop.load(in); 在Unix\Linux上 您可以使用file命令进行特定的扩展,并获得相应的映射 此时,您得到了properties对象中的所有映射。 享受吧
# 1 楼答案
如果你想打开一个包含相关程序的文件,你其实不需要知道相关的程序,因为Java可以使用Java为你做关联。awt。桌面类
# 2 楼答案
在窗口上:
在Unix\Linux上
您可以使用
file
命令进行特定的扩展,并获得相应的映射此时,您得到了properties对象中的所有映射。 享受吧