Re: saving as a .dat file
"ab" <abzno1@gmail.com> wrote in message
news:1164019936.521478.42290@h54g2000cwb.googlegroups.com...
You just want to iterate through your java.util.List<DVD> dvds = new
java.util.ArrayList<DVD>();
output 'all' your dvd variables into your .dat on one line separated by
a comma, so when you read a line you split it by comma giving you array
of your data items.
initialise your .dat file
for (DVD dvd : dvds) {
output dvd.title + ","
output dvd.genre + ","
etc.
output "\n" //new line
}
This will only work if you're certain that your DVD title, genre, etc.
do not contain commas. Otherwise, you'll need to invent some sort of
escaping mechanism to distinguish which commas are part of the data, and
which commas are seperators.
Or better yet, use a ready made library. What you're doing here is
called Comma Seperated Values, or CSV, and it's a problem people have
already solved. By using an existing library, you'll benefit from all the
bugs and issues that the authors have discovered and fixed, rather than
going through them yourself.
this is a simple way of doing what your after. You should really start
learning how to output your data as xml format.
XML might be good for this too, especially if you want to share your
file with other programs, or over the Internet. The idea is to use a
pre-existing library where possible to save you from issues you might not
have thought of.
- Oliver