Opening a text file

literally opening a text file

Page 1 of 1

4 Replies - 20873 Views - Last Post: 23 January 2009 - 06:58 PM Rate Topic: -----

#1 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Opening a text file

Posted 21 January 2009 - 06:47 PM

ok, this is probably one of those things that has an easy answer, however i cant seem to figure it out. I want to literally open a .txt file using java. The basic idea is once my program is done, a text file is opened to show the results. I do know that you can use the
 runTime.getexec("");
to open a .exe, but it doesnt work with a .txt file. Any ideas would be great! thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Opening a text file

#2 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Opening a text file

Posted 21 January 2009 - 07:24 PM

Just put notepad in front of the command.

For example if you had the file "myFile.txt"

you go to the directory in the command prompt and type notepad myFile.txt

Now I believe for text files the file extension is optional, but im not sure. But I do know for .java files and so on the extension is required.
Was This Post Helpful? 0
  • +
  • -

#3 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Opening a text file

Posted 22 January 2009 - 01:30 AM

here is the code for opening your text file in notepad under windows :
btw, the
runTime.getexec("");


is wrong, use the following instead:
Runtime.getRuntime().exec("notepad MyFile.txt");


here is the complete code snippet that you will be needing:
try{
		Runtime.getRuntime().exec("notepad MyFile.txt");
		}
		catch(IOException ex){
		ex.printStackTrace();
		}


I hope this helps, good luck in your program ;)
Was This Post Helpful? 0
  • +
  • -

#4 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Re: Opening a text file

Posted 23 January 2009 - 04:38 PM

Thanks so much for the help guys, now i can add the feature!
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Opening a text file

Posted 23 January 2009 - 06:58 PM

View Postpainkiller102, on 23 Jan, 2009 - 03:38 PM, said:

Thanks so much for the help guys, now i can add the feature!

try{
		Runtime.getRuntime().exec("notepad MyFile.txt");
		}
		catch(IOException e){
		}


Where you want it done in your code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1