Using Scanner class to write to Vectors
Right i've been messing around with this problem for a good few days, so i wonder if anyone here can help me out with it.
I have a Vector full of Electrical Device objects which are series of classes created by myself with items such as TV's, Computers, Lights etc... each containing several methods and variables.
I can save the vector to a .data file perfectly using the PrintWriter class but i'm stumped on how to use the Scanner file to read them back into the same vector (effectively a save/load function in my program).
I've been trying along the lines of;
Code:
try
{
File electricDevicesFile = new File("electricDevices.data");
Scanner fileReader = new Scanner(electricDevicesFile);
while(fileReader.hasNext())
{
electricDevices.addElement(fileReader.nextElectricDevice());
}
fileReader.close();
}
catch (FileNotFoundException fnfe)
{
JOptionPane.showMessageDialog(null, "File Not Found", "File Not Found", 0);
}
While i know full well nextElectricDevice() doesn't even exist, thats what i'm trying to get it to do. Get each electricDevices from file and add them to the vector one at a time.
Any Ideas?