简体   繁体   English

如何反序列化ArrayList的对象 <String[]> 在java中

[英]How to deserialize an object of ArrayList<String[]> in java

I have serialized an ArrayList and stored it to a file with extension .ser . 我已经序列化了ArrayList并将其存储到扩展名为.ser的文件中。 How can I deserialize the object and store it back into an ArrayList. 我如何反序列化对象并将其存储回ArrayList中。 I am getting an error Note: Hw5b.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 我收到错误Note: Hw5b.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Hw5b.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

//Serializing Object
ArrayList<String[]> list = new ArrayList<String []>();
FileOutputStream fout =  new FileOutputStream("movie-matrix2.ser");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(list);

//Deserializing Object
FileInputStream streamIn = new FileInputStream("movie-matrix2.ser");
ObjectInputStream objectInputStream =  new  ObjectInputStream(streamIn);
list = (ArrayList<String[]>)objectInputStream.readObject();

It's not an error. 这不是错误。 It's a warning. 这是一个警告。

For details, you could recompile with ecompile with -Xlint:unchecked, just as the message says. 有关详细信息,您可以使用-Xlint:unchecked与ecompile一起重新编译,就像消息中所说的那样。

But you can basically do nothing about that warning, except suppressing it: the compiler warns you that there is now way to ensure that the list you get is an ArrayList<String[]> . 但是您基本上可以对该警告采取任何措施,除非对其进行抑制:编译器警告您,现在有一种方法可以确保您得到的列表是ArrayList<String[]> Only that it's an ArrayList. 只是它是一个ArrayList。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM