黑马程序员24-5: DataInputStream输入数据流,

------- android培训 java培训、期待与您交流!-------


package cn.itcast.io.p5.datastream;

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

import java.io.FileOutputStream;
import java.io.IOException;

//不需要序列号,又要使用到基本数据类型的时候,用DataInputStream
public class DataSteamDemo {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
//		writeData();
		readData();
		
	}

	public static void readData() throws IOException {
		
		DataInputStream dis = new DataInputStream(new FileInputStream("data.txt"));
		
		String str = dis.readUTF();
		
		System.out.println(str);
	}

	public static void writeData() throws IOException {
		
		DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.txt"));
		
		dos.writeUTF("你好");
		
		dos.close();
		
		
	}

}



------- android培训 java培训、期待与您交流!-------


详细请查看: http://edu.csdn.net/heima -------

你可能感兴趣的:(datainputstream)