📄 frienddata.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -