📄 picture.java
字号:
package com.j2medev.ch8.mmapi;
import java.io.*;
public class Picture {
private String title = "";//标题
private byte[] img = null;//图片数据
public Picture() {
}
public Picture(String title,byte[] _img){
this.setTitle(title);
img = _img;
}
//序列化过程
public void serialize(DataOutputStream dos){
try{
dos.writeUTF(getTitle());
dos.writeInt(img.length);//将图片数据的长度写入
dos.write(getImg());
}catch(IOException ex){
ex.printStackTrace();
}
}
//反序列化过程
public static Picture deserialize(DataInputStream dis){
try{
Picture instance = new Picture();
instance.setTitle(dis.readUTF());
int length = dis.readInt();//读取图片数据的长度,方便生成数组
instance.img = new byte[length];
dis.read(instance.img);
return instance;
}catch(IOException ex){
ex.printStackTrace();
return null;
}
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public byte[] getImg() {
return img;
}
public void setImg(byte[] img) {
this.img = img;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -