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 there could be the Windows Paint or GIMP on the Linux operating system.
package org.kodejava.awt;
import java.awt.*;
import java.io.File;
import java.io.IOException;
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();
desktop.edit(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Latest posts by Wayan (see all)
- How do I create a servlet filter to make secure cookies? - April 18, 2024
- How do I configure secure cookies using web.xml? - April 18, 2024
- How do I create a table with multiple header in iText 8? - March 16, 2024