*This is the main class, i want the output display 2 name likes
- John ,ss,22
- Hon ,sxx,32
So anyone know how to use array @ list in this code?
private static final String filepath="C:\\Users\\im\\Desktop\\obj.txt";
public static void main(String args[]) {
Soalan1 objectIO = new Soalan1();
//List<List<String>> outter = new ArrayList<List<String>>();
//List<String> inner2 = new ArrayList<String>();
//List<int> Student = new List<int>();
Student slist = new Student("John","ss",22); <==== here i want change it to array/list
objectIO.WriteObjectToFile(filepath, slist);
//Read object from file
Student st = (Student) objectIO.ReadObjectFromFile(filepath);
System.out.println(st);
}
public void WriteObjectToFile(String filepath,Object serObj) {
try {
FileOutputStream fileOut = new FileOutputStream(filepath);
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
objectOut.writeObject(serObj);
objectOut.close();
System.out.println("The Object was succesfully written to a file");
} catch (Exception ex) {
ex.printStackTrace();
}
}
public Object ReadObjectFromFile(String filepath) {
try {
FileInputStream fileIn = new FileInputStream(filepath);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
Object obj = objectIn.readObject();
System.out.println("The Object has been read from the file");
objectIn.close();
return obj;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}