frienddata.java

来自「J2ME开发实例,内含有可直接运行的源程序代码,供大家学习参考」· Java 代码 · 共 54 行

JAVA
54
字号
import java.io.*;
class FriendData
{
	String name ;
	String tel ;
	boolean sex ;
	int age ;
	public FriendData()
	{
		name = "NO NAME" ;
		name = "NO TEL" ;
		sex = false ;
		age = 0 ;
	}
	public byte[] encode()
	{
		byte[] result = null ;
		try
		{
			ByteArrayOutputStream bos =
				new ByteArrayOutputStream() ;
			DataOutputStream dos =
				new DataOutputStream (bos) ;
			dos.writeUTF(name) ;
			dos.writeUTF(tel) ;
			dos.writeBoolean(sex) ;
			dos.writeInt(age) ;
			result = bos.toByteArray() ;
			dos.close() ;
			bos.close() ;
		}
		catch(Exception e)
		{ }
		return result ;
	}
	public void decode(byte[] data)
	{
		try
		{
			ByteArrayInputStream bis =
				new ByteArrayInputStream(data) ;
			DataInputStream dis =
				new DataInputStream (bis) ;
			name = dis.readUTF() ;
			tel = dis.readUTF() ;
			sex = dis.readBoolean() ;
			age = dis.readInt() ;
			dis.close() ;
			bis.close() ;
		}
		catch(Exception e)
		{ }
	}
}

⌨️ 快捷键说明

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