1

In my Swing application I have an action which opens a file with the system application

Desktop.getDesktop().open(myFile);

This action must be disabled when no application is registered for this file. I cann't understand how to get this information before the application has been launched (after that I get this information when an IOException is thrown).

Sergiy Medvynskyy
  • 11,160
  • 1
  • 32
  • 48
  • If your application is not supposed to open all files , you could try using https://docs.oracle.com/javase/7/docs/api/javax/swing/filechooser/FileFilter.html to restrict the files the application could open – R.G Nov 11 '15 at 10:01
  • @RanjitGopinathan Unfortunatelly my application is supposed to open all files (files are saved in our cloud, so I have no `JFileChooser` to use `FileFilter`). – Sergiy Medvynskyy Nov 11 '15 at 10:05
  • What operating system? – Jonny Henly Nov 11 '15 at 10:10
  • @JonnyHenly Windows + MacOS – Sergiy Medvynskyy Nov 11 '15 at 10:11
  • Have you tried checking file associations in the registry on Windows: [Utilising a file association in a Java application](http://stackoverflow.com/questions/2043029/utilising-a-file-association-in-a-java-application)? I'm not sure about MacOS. – Jonny Henly Nov 11 '15 at 10:13
  • On Mac OS X, scan the output of [`lsregister -dump`](http://krypted.com/mac-security/lsregister-associating-file-types-in-mac-os-x/). – trashgod Nov 11 '15 at 10:43

0 Answers0