假設serialise.bin是一個文件,是滿語的,被一個ArrayList時,它是序列化反序列化文件,然後將內容存儲在ArrayList <String>中。 (JAVA)
public static ArrayList<String> deserialise(){
ArrayList<String> words= new ArrayList<String>();
File serial = new File("serialise.bin");
try(ObjectInputStream in = new ObjectInputStream(new FileInputStream(serial))){
System.out.println(in.readObject()); //prints out the content
//I want to store the content in to an ArrayList<String>
}catch(Exception e){
e.getMessage();
}
return words;
}
我希望能夠deserialise了「serialise.bin」文件和存儲內容在一個ArrayList
你的問題是什麼?你的代碼有問題嗎? – shmosel
不要返回'ArrayList'。相反,返回List,這樣'deserialise'的調用者就不會依賴於那個實現細節。 –