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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Output to text file" Watch "Output to text file" New topic

Output to text file

Simon Knight

Joined: Mar 04, 2004
Posts: 25

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?


Dmitry Melnik
Ranch Hand

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

Thanks. You are right. Fixed
I agree. Here's the link:
subject: Output to text file
Similar Threads
Reading of file contents and then outputting it into a database
write output to an xml file
help me the code
Looking for utility program find strings..
How to convert JSP into a txt or html file?