wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes formatting data, and saving same to external file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "formatting data, and saving same to external file" Watch "formatting data, and saving same to external file" New topic

formatting data, and saving same to external file

srinivas nama

Joined: Aug 20, 2001
Posts: 3
I have to retrieve the data from database, format it, and save the data to external file in csv format... and I am new to java.
Ganesh Ram
Ranch Hand

Joined: Jul 20, 2001
Posts: 33
To read from a database, you need JDBC. Please read up on how to connect to a database and perform query etc. you can find examples at javasoft.
Formatting would be write each of the relevant columns or any computation performed into a StringBuffer appending commas after every column.
stringbuffer sb = new stringbuffer();
To write to a file, use outputstream.
Fileoutputstream f = Fileoutstream(filename).
bufferedwriter b = new bufferedwriter(new outputstreamwriter(f));
watch all the cases(lower and upper), i am writing this more as a draft.
Richard Rodger

Joined: Jan 07, 2005
Posts: 17
The easiest way is to use a CSV component that does this. There are many if you search google.

Richard Rodger<br /><a href="http://www.ricebridge.com" target="_blank" rel="nofollow">http://www.ricebridge.com</a>
I agree. Here's the link: http://aspose.com/file-tools
subject: formatting data, and saving same to external file
Similar Threads
how can i resultset data to text file in a table format
Including images directly in HTML files
Updating the info from other sites to XML file
reading and parsing fixed length file
Parsing data file to XML?