-1

I am trying to get the associated program of a file, for example if I have a file C:/foo/bar.example I want to get what program opens .example (Kind of like Notepad.exe opens .txt Files).

I tried creating a process to open that file using runtime.exec("rundll32 url.dll,FileProtocolHandler C:/foo/bar.example") but there is no way to get the associated application using Process.

This example shows what I am trying to achieve in Windows, although I want something cross platform.

hms11
  • 54
  • 6
  • 1
    Related [How to open user system preferred editor for given file?](https://stackoverflow.com/questions/526037/how-to-open-user-system-preferred-editor-for-given-file), but without a documented way to determine what application was run. – Joe Aug 24 '20 at 13:57
  • .example is a Java application? Is it a jar file? – Carlos Bazilio Aug 24 '20 at 13:59
  • 1
    I don't think there is a general answer for every OS. But maybe the answer [here](https://stackoverflow.com/a/13576250/11905620) might help you for Windows. – MaS Aug 24 '20 at 14:24
  • @MaS does not work for Java 11/12 – KUSH42 Aug 24 '20 at 14:29

1 Answers1

2

I do not think that this is possible just using pure Java.

The only way that comes to my mind right now (using Java) is to use JNA to directly interface with the Win32-API (note that this is written in C and not Java). See this answer for how to achieve the Win32-API-part and this link for how to use JNA.

KUSH42
  • 552
  • 2
  • 13