?? 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 + -