aspose file tools*
The moose likes Beginning Java and the fly likes Output to text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Output to text file" Watch "Output to text file" New topic
Author

Output to text file

Simon Knight
Greenhorn

Joined: Mar 04, 2004
Posts: 25
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

Joined: Dec 18, 2003
Posts: 328
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

Joined: Jun 21, 2004
Posts: 153
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


-Dan
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
you had to use outFile.close();

Thanks. You are right. Fixed
 
wood burning stoves
 
subject: Output to text file