i 绝望

依然

Miss Lang

java代码字符字节流

总结:

package com.aini;

import java.io.IOException;
import java.io.InputStreamReader;
//流类 
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.FileInputStream;
import java.util.InpuStreamReader;

public class udf {
	public static void main(String[] args) throws Exception {
		readabc();
		eeread();
	}

	// 常用字符编码读取
	private static void readabc() throws IOException {// 字符读取流文件
		InputStreamReader isr = new InputStreamReader(new FileInputStream(
				"E:\\utf.txt"), "utf-8");
		char[] buf = new char[1024];
		int len = isr.read(buf);// 有流的地方就有异常
		String s = new String(buf, 0, len);
		System.out.println(s);
		// 写入
	}

	public static void writeabc() throws Exception {
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(
				"E:\\utf.txt"), "utf-8");
		osw.write("你好");
		osw.close();

	}// 字节流//读取方法

	public static void eeread() throws Exception {
		DataInputStream dis = new DataInputStream(new FileInputStream(
				"E:\\utfdata.txt"));
		String s = dis.readUTF();// 字符串型时,只有readUTF()方法
		System.out.println(s);
		dis.close();

		// 读取int .boolean.double
	}

	public static void writeaa() throws Exception {
		DataInputStream dis = new DataInputStream(new FileInputStream(
				"E:\\te.txt"));
		int num = dis.readInt();// 整型
		boolean flag = dis.readBoolean();// 布尔型
		Double dd = dis.readDouble();// 大写double也是一类型???
		System.out.println(num + "\\" + flag + "\\" + dd);

	}// 写入int ,double.booleanr//数据流,dateInputStream

	public static void readaa() throws IOException {
		DataOutputStream dos = new DataOutputStream(new FileOutputStream(
				"E:\\data.txt"));
		dos.writeInt(234);
		dos.writeBoolean(false);
		dos.writeDouble(2.2);
		dos.close();

	}
}

  

posted on 2013-11-10 10:56  juewang  阅读(253)  评论(0编辑  收藏  举报

绝望依然

Miss Lang