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 Java 8 in Action this week in the Java 8 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
Author

formatting data, and saving same to external file

srinivas nama
Greenhorn

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));
b.writeline(sb.toString());
watch all the cases(lower and upper), i am writing this more as a draft.
Richard Rodger
Greenhorn

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
Parsing data file to XML?
Updating the info from other sites to XML file
Including images directly in HTML files
reading and parsing fixed length file
how can i resultset data to text file in a table format