How to open the notepad file in java?

guilgamos picture guilgamos · Aug 15, 2010 · Viewed 61k times · Source

I want to open Notepad in my Java program. Suppose that I have one button if I click this button the notepad will appear. I already have a file name and a directory.

How can I implement this case?

Answer

whiskeysierra picture whiskeysierra · Aug 15, 2010

Try

if (Desktop.isDesktopSupported()) {
    Desktop.getDesktop().edit(file);
} else {
    // I don't know, up to you to handle this
}

Make sure the file exists. Thanks to Andreas_D who pointed this out.