-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

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.