Help with using a jbutton actionlistener to open a text file
Hey Guys,
I've been building a contact editor GUI using Netbeans 7, and I'm stuck on how to open a text file with a button. I've searched around, but only found advice relating to jfilechooser. The text file contains all the entries submitted to the contact editor, and I don't need it to be opened within the GUI, just with notepad outside of the program.
Any help is appreciated!
Re: Help with using a jbutton actionlistener to open a text file
Quote:
how to open a text file with a button
The button's action listener method would call a method in one of the following classes.
Quote:
with notepad outside of the program.
Look at the Desktop class. It will ask the OS to provide the program to open a file.
If you want to specify which program to use, see the Process and Runtime classes where you can specify the full ccommand line to be executed.
Re: Help with using a jbutton actionlistener to open a text file
Why do you need to open the file in Notepad? Why can't you display the file on a JTextArea or a JEditorPane?
If you are determined to use Notepad then you can investigate Runtime.exec but make sure you google "pitfalls of runtime exec" or something similar.