This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Writing to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing to a file" Watch "Writing to a file" New topic
Author

Writing to a file

Jojo Wilson
Greenhorn

Joined: May 05, 2004
Posts: 2
What is an example of a way to create a file and write some text to it?
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
The moderators don't usually approve of just supplying code, but this is an instance where it's just easer if i give you this... This will right a string "s" to a file with the name (again a string) "filename". if no such file exists, it will create one.

the following static method will then read the filename String f and return the contents as a String, which you can partition into the information you need.

Don't tell anyone i gave you a hand-out


I've heard it takes forever to grow a woman from the ground
Jojo Wilson
Greenhorn

Joined: May 05, 2004
Posts: 2
I got it using ObjectOutputStream instead of PrintWriter. I appreciate your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing to a file