package edu.exam14.ex06data_buffer;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class DataBufferFilterStream {
	public static void main(String[] args) throws IOException {
		// user -> dOut -> bOut -> out ->MyData.bin
		OutputStream out = new FileOutputStream("MyData.bin");
		BufferedOutputStream bOut = new BufferedOutputStream(out);

		DataOutputStream dOut = new DataOutputStream(bOut);

		dOut.writeInt(9999);
		dOut.writeDouble(1.125);
		dOut.writeChars("aaa");

		dOut.close();

		// 읽어보자
		InputStream in = new FileInputStream("MyData.bin");
		BufferedInputStream bIn = new BufferedInputStream(in);
		DataInputStream dIn = new DataInputStream(bIn);

		int num = dIn.readInt();
		double dNum = dIn.readDouble();
		byte[] bStr = new byte[100];
		dIn.read(bStr);
		String str = bStr.toString();

		dIn.close();
		System.out.println(num);
		System.out.println(dNum);
		System.out.println(str);
	}
}

'JAVA > java 예제' 카테고리의 다른 글

StreamBufferWriter/Reader 예제  (0) 2020.01.29
Char Writer/Reader Stream 예제  (0) 2020.01.29
BufferedFileStream 예제  (0) 2020.01.29
DataFilterStream 예제  (0) 2020.01.29
bytefile / bufferfile 예제  (0) 2020.01.29

+ Recent posts