winner.java

来自「j2me的一款钓鱼的游戏」· Java 代码 · 共 60 行

JAVA
60
字号
package Kidfishing;

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

public class Winner {
	String name;
	int count;

	public Winner(String name, int count) {
		this.name = name;
		this.count = count;
	}

	public Winner(byte[] temp) {
		getData(temp);
	}

	public byte[] getByte() {
		byte temp[] = null;

		ByteArrayOutputStream abos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(abos);

		try {
			dos.writeUTF(name);
			dos.writeInt(count);

			temp = abos.toByteArray();

			abos.close();
			dos.close();
		} catch (IOException e) {

			e.printStackTrace();
		}

		return temp;
	}

	public void getData(byte[] temp) {
		ByteArrayInputStream abis = new ByteArrayInputStream(temp);

		DataInputStream dis = new DataInputStream(abis);

		try {
			name = dis.readUTF();
			count = dis.readInt();
			abis.close();
			dis.close();
		} catch (IOException e) {

			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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