This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening a text file in wordpad from a button click

 
Stephanie Lee
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks billy! i got it. it worked!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic