【发布时间】:2013-12-13 19:23:15
【问题描述】:
我保存了一个包含 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) What have you tried? 我的意思是除了问我们。 2) 为了尽快获得更好的帮助,请发帖SSCCE。
-
几乎相同,但使用
ObjectInputStream而不是ObjectOutputStream。 -
应该是
JOptionPane.showMessageDialog(this, arrayT); -
这段代码的问题是?
标签: java arrays serialization