📄 bookaccount.java
字号:
/* * 基本的记录字段分割和转换字节数组 */package PhoneBook;import java.io.*;public class BookAccount { private String userName = ""; private String mobilePhone = ""; private String email = ""; private String phone = ""; public BookAccount(String userName, String mobilePhone, String email, String phone) { this.userName = userName; this.mobilePhone = mobilePhone; this.email = email; this.phone = phone; } public BookAccount() { } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getMobilePhone() { return mobilePhone; } public void setMobilePhone(String mobilePhone) { this.mobilePhone = mobilePhone; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public byte[] serialize() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeUTF(userName); dos.writeUTF(mobilePhone); dos.writeUTF(email); dos.writeUTF(phone); baos.close(); dos.close(); return baos.toByteArray(); } public static BookAccount deserialize(byte[] data) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(data); DataInputStream dis = new DataInputStream(bais); BookAccount account = new BookAccount(); account.userName = dis.readUTF(); account.mobilePhone = dis.readUTF(); account.email = dis.readUTF(); account.phone = dis.readUTF(); bais.close(); dis.close(); return account; } public static boolean matches(byte[] data, String userName) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(data); DataInputStream dis = new DataInputStream(bais); try { return (dis.readUTF()).equals(userName); } catch (IOException e) { e.printStackTrace(); return false; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -