Java Tips: How to open a file with default editor from Java applications

By Angsuman Chakraborty, Gaea News Network
Monday, February 8, 2010

For a long time we couldn’t easily use Java applications to open the default (for the operating system) editor application (like notepad in Windows Operating Systems for text files). Starting with JDK 1.6 you can use the java.awt.Desktop class to easily launch the default editor (of your operating system) from Java applications. Read below for more details and the code.

java.net.URI uri = new URI(”https://gaeatimes.com“);
java.awt.Desktop.getDesktop().edit(new File(”Readme”));

The documentation for edit() states: Launches the associated editor application and opens a file for editing.

Note: The EDIT action is not supported in CentOS 5.x systems. Let us know if you have success on your Operating System.

Did you like this tip? Consider subscribing to our site for more such tips.

Discussion

fred
March 13, 2010: 12:22 pm

Edit action doesn’t work on ubuntu 9.10.

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :