我正在尝试序列化一个包含一个ImageIcon
(实现可序列化)的对象。该图像是 ubuntu 的示例图像,大小约为 320k。
public static void write() {
ImageIcon aww = null;
aww = new ImageIcon("/home/javi/PRUEBA/img.jpg");
ab hue = new ab("hola", "adios", 10, 1111, aww);
ObjectOutputStream oos = null;
FileOutputStream a = null;
try {
a = new FileOutputStream("/home/javi/PRUEBA/mapa.atd");
oos = new ObjectOutputStream(a);
oos.writeObject(hue);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
a.close();
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class ab implements Serializable {
private static final long serialVersionUID = -4377893644898458425L;
String asdf;
String b;
int w;
Integer ab;
ImageIcon a;
public ab(String asdf, String b, int w, Integer ab, ImageIcon ww) {
super();
this.asdf = asdf;
this.b = b;
this.w = w;
this.ab = ab;
a = ww;
}
}
这是我正在使用的代码,我不知道为什么图像约为320k而输出文件约为10Mb。如果需要,我可以上传 img ( /usr/share/unity-2d/warty-final-ubuntu.jpg
)