File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Printing to File? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printing to File?" Watch "Printing to File?" New topic

Printing to File?

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Hello again.

I know that if i have some loop, for example, i can prints something out e.g. elements in an array, to the screen. Is it possible to instead printing these elements to the screen, print to a text file???

BAsically, is there a way to print to a file as oppsed to the screen?

Thank you!

Moosey knows best
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
Java Considers the System.out as a Stream so is a File. Create a BufferedWriter with FileOutputStream and it will print the data to a file. See API for more help on these. Is should be simple. Tell me if you face trouble

-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You should check out the I/O Trail from the Java tutorial (see link in my sig). This should help you understand how writing to a file is similar to writing to the screen (at least if you have been using the I/O Stream API already).


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Printing to File?
It's not a secret anymore!