IO 스트림 DataInputStream 및 DataOutputStream은 기본 데이터 유형을 조작하는 데 사용됩니다.

1570 단어 java 기초
DataInputStream 및 DataOutputStream을 통해 기본 데이터 유형을 손쉽게 조작
/*
DataInputStream DataOutputStream

 。

*/
import java.io.*;
class DataStreamDemo 
{
	public static void main(String[] args) throws IOException
	{
		//writeData();
		//readData();

		//writeUTFDemo();

//		//OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("gbk.txt"),"gbk");
//
//		//osw.write(" ");
//		//osw.close();

//		readUTFDemo();

	}
	public static void readUTFDemo()throws IOException
	{
		DataInputStream dis = new DataInputStream(new FileInputStream("utf.txt"));

		String s = dis.readUTF();

		System.out.println(s);
		dis.close();
	}



	public static void writeUTFDemo()throws IOException
	{
		DataOutputStream dos = new DataOutputStream(new FileOutputStream("utfdate.txt"));

		dos.writeUTF(" ");// UTF-8 .readUTF , 

		dos.close();
	}

	public static void readData()throws IOException
	{
		DataInputStream dis = new DataInputStream(new FileInputStream("data.txt"));
                // , 
		int num = dis.readInt();
		boolean b = dis.readBoolean();
		double d = dis.readDouble();

		System.out.println("num="+num);
		System.out.println("b="+b);
		System.out.println("d="+d);

		dis.close();
	}
	public static void writeData()throws IOException
	{
		DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.txt"));
                // 
		dos.writeInt(234);    
		dos.writeBoolean(true);
		dos.writeDouble(9887.543);

		dos.close();

		

		
	}
}

좋은 웹페이지 즐겨찾기