I have a problem with reading from a text file to an arraylist. The problem is that i don't know how to read in multiple types, because in my arraylist there are Points, Strings, booleans, therefor linesplit doesn't work. I checked all the topics and didn't find a solution to this.
edit: Elrendezes class looks like
class Elrendezes {
protected Point Po;
protected String hely;
protected String foglalo;
protected boolean foglalt;
}
Here's how my file looks like:
java.awt.Point[x=16,y=13], 1, name1, false
And the method to read is
public static ArrayList<Elrendezes> readDataFromFile(){
ArrayList<Elrendezes> ElrList = new ArrayList<Elrendezes>();
FileInputStream fstream = null;
try
{
fstream = new FileInputStream("src/files/DataFile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine = null ;
String tokens[] = strLine.split(", ");
while ((strLine = br.readLine()) != null) {
tokens = strLine.split(", ");
// THIS DOES NOT WORK: ElrList.add(new Elrendezes(tokens[0], tokens[1], tokens[2], tokens[3]));
}
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try { fstream.close(); } catch ( Exception ignore ) {}
}
return ElrList;
}
THIS DOES NOT WORKwhat doesn't work can please say a little bit about the error you are getting