I have a ptoblem i have 3 types of data in one file for example car data , van data , truck data. The problem is i have to have a flag to check what data is next and set a variable , so we know what object to create and store.
Each data says with a "[" , followed by either a C , V ([Car data])
Java Code:
else if(lineOfText.startsWith("[V") && (lineOfText.startsWith("[T"))) // flag
{
lineOfText = null; //setting the variable to record the data
}
else
{
Scanner scanner2 = new Scanner(lineOfText);
scanner2.useDelimiter("[ ]*,[ ]*");
Vehicle newV = new Car();
newV.readData(scanner2); // Read in the line of data.
vehicleList.add(newV); // Store in the array.
scanner2.close();
//System.out.println(lineOfText);
}
}
scanner.close();
}