• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

opening a text file in wordpad from a button click

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks billy! i got it. it worked!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic