我保存了一個包含3個陣列(1個String
和2個Double
)的序列化String
陣列的文件。讀取序列化陣列陣列
我該如何讀取它並重做3個數組?
我是這樣寫的:
String[] storeAllArrays[] = {prod, cant, pret};
ObjectOutputStream out;
try {
out = new ObjectOutputStream(new FileOutputStream("test.ser"));
out.writeObject(storeAllArrays);
out.flush();
out.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(Test2.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Test2.class.getName()).log(Level.SEVERE, null, ex);
}
編輯:這裏是我的嘗試:
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream("test.ser"));
String[] arrayT = (String[]) in.readObject();
in.close();
JOptionPane.showMessageDialog(this, ArrayT);
} catch (IOException ex) {
Logger.getLogger(Test2.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Test2.class.getName()).log(Level.SEVERE, null, ex);
}
1)你嘗試過什麼? ](http://www.whathaveyoutried.com/)我的意思是*除了*問我們。 2)爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 –
幾乎相同,但用ObjectInputStream而不是ObjectOutputStream。 – m0skit0
它應該是'JOptionPane.showMessageDialog(this,arrayT);' – kukido