javaOOp 字符流读取文件

package cn.happy3;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Day01 {

	/**
	 * 1.字符流读取文件
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		FileReader reader=new FileReader("E:/S2226.txt");
		char[] chars=new char[1024];
		int data;
		while((data=reader.read(chars))!=-1){
			String temp=new String(chars,0,data);
			System.out.println(temp);
		}
		reader.close();
		

	}

}

package cn.happy3;

import java.io.FileWriter;
import java.io.IOException;

public class Day02 {

	/**
	 *  FileWriter 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		FileWriter writer=new FileWriter("E:/S2226.txt");
		String words="呵呵";
		writer.write(words);
		writer.close();
		

	}

}

你可能感兴趣的:(javaOOp 字符流读取文件)