Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know any file/program is associated with which default program by Java?

Tags:

java

I just wantto know how can I know the default program associated with any external program/file. For ex-by default, a java file opens with which program? This I have to know using a Java program itself.

like image 743
kushpf Avatar asked May 21 '26 06:05

kushpf


1 Answers

On windows:

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);

on Unix\Linux:

you can use file command for specific extension and get the corresponding mapping.

at this point you got all the mappings in your properties object. enjoy!

like image 132
aviad Avatar answered May 23 '26 21:05

aviad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!