View Single Post
  #2 (permalink)  
Old 01-05-2009, 10:53 PM
Steve11235's Avatar
Steve11235 Steve11235 is offline
Senior Member
 
Join Date: Dec 2008
Posts: 972
Rep Power: 2
Steve11235 is on a distinguished road
Default
I may not fully understand what you need to do, so if I whiff, just ignore me...

I suggest separating your fields with tab characters '\t' and data rows with new lines. I assume your user is on Windows, so that is "\r\n".

Make sure you always write out the full number of tabs, even if there is no data at the end of the line.

To recover the data, read a certain number of lines back into a String. You can read them all at once if the output file is not too large. Use String.split("\\r\\n") (escape the backslashes) to get an array of String, one for each record. On each record, use String.split("\\t") to get an array of String for each field. This is a very easy way to recover the data.

Your user can open the file using Excel. You can output a row of column headings in the first record if you want.

If you have multiple types of records, you can use the same approach, just make the first field a record type indicator, so you know what to expect when you read it back in.

I hope that helps...
Reply With Quote