java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to 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 Desktop.edit(File file) method. On the code below we will edit a PNG file, this call will execute registered program such as the Windows Paint or GIMP on Linux operating system.

package com.javacoderanch.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) {