Home Java Example Java Awt Open The Default Editor to Edit the File



Open The Default Editor to Edit the File
Posted on: June 13, 2009 at 12:00 AM
This section, you will see the method of opening the file in the default editor to edit and save the file.

Open The Default Editor to Edit the File

     

This section, you will see the method of opening the file in the default editor to edit and save the file. Here an example has been provided with the complete Java code for illustrating all the things that helps to open the file in the default editor to edit the file.

When you run the application this will need the file name with the complete path where it exists in your system. And then the application will open the file in the default editor.

Code Description:

Here as you can see the Desktop class is used for launching the file in the default editor to edit. This class allows Java Application to launch associated applications registered on the native desktop to handle a URI or a file. It's edit method opens the file in the default editor to edit.

Here is the code of the program:

import java.awt.Desktop;
import java.io.*;

public class OpenDefaultEditorToEditFile {
  public static void main(String[] a) {
  String filename = "";
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the file name with complete path: ");
  try {
  filename = in.readLine();
  File file = new File(filename);
  if(!file.exists() && file.length() 0){
  System.out.println("Specified file does not exist!");
  System.exit(0);
  }
  Desktop desktop = null;
  if (Desktop.isDesktopSupported()) {
  desktop = Desktop.getDesktop();
  }
  desktop.edit(file);
  }
  catch (IOException ioe) {
  ioe.printStackTrace();
  }
  }
}

Download the Example

Related Tags for Open The Default Editor to Edit the File:
javaccomfileideeditorhelpdefaultviidopeneditforexamplewithtoediexameilratingitulpecompletefaultinasmpstrthinletjallpenprotorxaxampseeathallmplcodcodestrvassthavstatihatefaultpleplprodeomo


More Tutorials from this section

Ask Questions?    Discuss: Open The Default Editor to Edit the File   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.