Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output to text file

 
Simon Knight
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I'm trying to finish an assignment and need to write up some test results. I'd like to know if it's possible to send the screen output directly to a text file so I don't have to sit and type it all in.

Can anyone tell me if this is possible and how it is done.
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Windows:

you can copy to the system clipboard your program's output from it's console window, and then paste it to a text file opened in a text editor, or

you can run your program like this: c:\>java yourclass >out.txt, or

you can modify your code to make the program output to the text file. Here is a piece of code as an example:



[ July 20, 2004: Message edited by: Dmitry Melnik ]
[ July 20, 2004: Message edited by: Dmitry Melnik ]
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dmitry, 2 things:
1)I had never known that you could use c:\>java yourclass >out.txt it is very helpful and I'm glad I ran across your reply to Simon.
2)when using a printstream I thought you had to use outFile.close(); or is that just optional?

Thanks-Dan
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you had to use outFile.close();

Thanks. You are right. Fixed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic