consider i have 2 different classes
public class A {
String name;
int A1;
int A2;
}
and the other class is:
public class B {
String B0;
int B1;
int B2;
}
and now i have a file which contains an integer, and several object of A and several of B
The file could be like
3
"Jim"; 1;2
"jef";3;5
"Peter";6;7
"aa";1;1
"bb";2;3
"cc";3;4
You can consider that the3 (in the beginning of the file)is the number of objects in class A and the rest are objects from class B.
The question is, how can i read and separate all objects from the file?
The main problem is that i don't know how can i read the first int from the file. what i did is
InputStream inputFileStream = Main.class.getResourceAsStream("/inputFile.txt");
ObjectInputStream ois = new ObjectInputStream(inputStream);
int i = ois.readInt();
ois.close();
but it gives me an error:
Exception in thread "main" java.io.StreamCorruptedException: invalid stream header: 350A4261