aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes opening a text file in wordpad from a button click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "opening a text file in wordpad from a button click" Watch "opening a text file in wordpad from a button click" New topic
Author

opening a text file in wordpad from a button click

Stephanie Lee
Greenhorn

Joined: Jan 22, 2004
Posts: 7
i have a button im my swing application where i want it to open a text file in wordpad when it is clicked. so far i have:
if(e.getSource() == pktLogButton)
{
try{
String s = "PktLog.txt";
Process p = Runtime.getRuntime().exec("wordpad.exe " + s);
}
catch(IOException e2){
e2.printStackTrace();
}
}
for some reason i get an error. but it works if i use
Process p = Runtime.getRuntime().exec("notepad.exe " + s);
but i don't want to open it in notepad because it doesn't show any special characters. so how can i get wordpad to open the text file? any help is much appreciated.
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
wordpad isn't in your PATH, so you'd have to specify where wordpad is. It's just like going to the command prompt and typing:
wordpad.exe filename
It gives you an error right?
On the other hand, if you were to type:
\path\to\it\wordpad.exe filename
it would work. So you have to do the same thing programmatically. Or add the directory containing wordpad.exe to your PATH (not classpath).
Stephanie Lee
Greenhorn

Joined: Jan 22, 2004
Posts: 7
thanks billy! i got it. it worked!
 
wood burning stoves
 
subject: opening a text file in wordpad from a button click