aspose file tools*
The moose likes Beginning Java and the fly likes writing to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writing to a file" Watch "writing to a file" New topic
Author

writing to a file

Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
Can anyone tell me how i can write a string to a file?
I've already got

but clearly in is an InputStream and saveTable.getText(); is a string. How can i get around this?


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Aleksey Matiychenko
Ranch Hand

Joined: Apr 03, 2001
Posts: 178
You do not need InputStream in this case at all. You just write a string. Check the methods on FileOutputStream.
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
Better yet, if you are only writing character data, you should use Writers, specifically the BufferedWriter...
String text = "This is text to write to file.";
File = new File("yourfile.whatever");
FileWriter fw = new FileWriter(file);
BufferedWriter writer = new BufferedWriter(fw);
writer.write(text);
writer.close();
FileWriter will do this by itself, but the BufferedWriter povides some buffering for more efficiency.
Hope this helps.


- Chris Stehno, SCPJ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing to a file