-1

i have a file that has a lot of data. In this file i don't want to write something but i want to write that data of the file in my array list full of objects. So far i have manage to write only this code:

  try{
  FileInputStream fis = new FileInputStream("data.csv");
  ObjectInputStream ois = new ObjectInputStream(fis);
  ArrayList<Hotell> part_5= (ArrayList<Hotell>) ois.readObject();
  System.out.println(part_5);
  ois.close();
 }catch(NumberFormatException ex){}

But when i am going to excute the programm nothing appears

In the file i hava fields like id, name of hotel , stars

I think BufferedReader is okey to use it but i don't know how because i want to save my file into arraylist full of objects

The_elevator
  • 75
  • 1
  • 8

1 Answers1

1

ObjectInputStream deserializes Object primitives that were written with ObjectOutputStream. To read your .csv file in and populate your ArrayList objects, you are going to have to use something like BufferedReader, process the input, and populate your ArrayList objects programmatically.

Justin Pearce
  • 4,994
  • 2
  • 24
  • 37