⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 account.java

📁 J2ME的源码!我以前学习J2ME的源码哈!非常适合初学者
💻 JAVA
字号:
package rms;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class Account {
	private String name;
	private String tel;
	private String mobileTel;
	private String email;
	
	public Account() {
		
	}
	
	public Account(String name, String tel, String mobileTel, String email){
		this.name = name;
		this.tel = tel;
		this.mobileTel = mobileTel;
		this.email = email;
	}
	
	public byte[] encode() {
		// 将上述字段转化为byte[]
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(bos);
		try {
			dos.writeUTF(name);
			dos.writeUTF(tel);
			dos.writeUTF(mobileTel);
			dos.writeUTF(email);
			byte[] data = bos.toByteArray();
			dos.close();
			bos.close();
			return data;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Account decode(byte[] data) {
		ByteArrayInputStream bis = new ByteArrayInputStream(data);
		DataInputStream dis = new DataInputStream(bis);
		try {
			String name = dis.readUTF();
			String tel = dis.readUTF();
			String mobileTel = dis.readUTF();
			String email = dis.readUTF();
			Account account = new Account(name, tel, mobileTel, email);
			return account;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobileTel() {
		return mobileTel;
	}

	public void setMobileTel(String mobileTel) {
		this.mobileTel = mobileTel;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -