How to write an ArrayList of Strings into a text file?

后端 未结 7 1111
不思量自难忘°
不思量自难忘° 2020-11-27 15:47

I want to write an ArrayList into a text file.

The ArrayList is created with the code:

ArrayList arr = new A         


        
7条回答
  •  眼角桃花
    2020-11-27 16:20

    If you want to serialize the ArrayList object to a file so you can read it back in again later use ObjectOuputStream/ObjectInputStream writeObject()/readObject() since ArrayList implements Serializable. It's not clear to me from your question if you want to do this or just write each individual item. If so then Andrey's answer will do that.

提交回复
热议问题