How do I edit a file using the default registered application?

For editing a file using the default registered or associated application we can do a call to the java.awt.Desktop.edit(File) method. In the code snippet below we will edit a PNG file. Using the edit() method of the Desktop class will open the default registered application for PNG files. For example on Windows the could be the Windows Paint or GIMP on the Linux operating system.

package org.kodejava.example.awt;

import java.awt.*;

public class RunningDefaultAppEdit {
    public static void main(String[] args) {
        File file = new File("logo.png");
        try {
            // Edit a file using the default program for the file type. In the example 
            // we will launch a default registered program to edit a PNG image.
            Desktop desktop = Desktop.getDesktop();
        } catch (IOException e) {

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.