上边学习了使用POI读取Excel文件,这篇讨论如何将读取到的数据写入二进制文件

1.将数据写入二进制文件

public void wirteBinary() {
	try {
		DataOutputStream os = new DataOutputStream(
				new BufferedOutputStream(new FileOutputStream(
						"E:\\data.dat")));
		os.writeInt(1001);
		os.writeByte(520);
		os.writeBoolean(true);
		os.writeFloat(10.0f);
		os.writeLong(100l);
		os.writeUTF("读写二进制文件");

		os.flush();
		os.close();

	} catch (IOException e) {

	}
}

2.从文件中读取二进制数据

public void readBinary() {
	try {
		DataInputStream is = new DataInputStream(
				new BufferedInputStream(new FileInputStream(
						"E:\\data.dat")));
		System.out.println(is.readInt());
		System.out.println(is.readByte());
		System.out.println(is.readBoolean());
		System.out.println(is.readFloat());
		System.out.println(is.readLong());
		System.out.println(is.readUTF());

		is.close();
	} catch (IOException e) {

	}
}

看一下程序执行的结果: