Java/Excercise

javaio ch05 DataStreamTest

낭구리 2021. 9. 13. 17:57
package ch05;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class DataStreamTest {

	public static void main(String[] args) {

		try (FileOutputStream fos = new FileOutputStream("data.txt");
				DataOutputStream dos = new DataOutputStream(fos);) {
			dos.writeByte(100);
			dos.writeChar('A');
			dos.writeInt(10);
			dos.writeFloat(3.14f);
			dos.writeUTF("TEST");

		} catch (IOException e) {
			System.out.println(e);
		}

///////////////////////////////////////

		try (FileInputStream fis = new FileInputStream("data.txt"); DataInputStream dis = new DataInputStream(fis)) {
			System.out.println(dis.readByte());
			System.out.println(dis.readChar());
			System.out.println(dis.readInt());
			System.out.println(dis.readFloat());
			System.out.println(dis.readUTF());

		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

'Java > Excercise' 카테고리의 다른 글

dataStructure ch01 DataStructureTest1  (0) 2021.09.14
javaio ch05 SerializationTest  (0) 2021.09.13
javaio ch05 BufferedStreamTest  (0) 2021.09.13
javaio ch05 InputStreamReaderTest  (0) 2021.09.13
javaio ch04 FileWriterTest  (0) 2021.09.13