java例程练习(字符流)

import java.io.*;

public class TestFileReader {
	public static void main(String[] args) {
		FileReader fr = null;
		int c = 0;
		try {
			fr = new FileReader("C:/java/Test.java");
			
			while((c = fr.read()) != -1) {
				System.out.print((char)c);
			}
			fr.close();
		} catch (FileNotFoundException e) {
			System.out.println("找不到指定文件");
		} catch (IOException e) {
			System.out.println("文件读取错误");
		}
	}
}
import java.io.*;


public class TestFileWriter {
	public static void main(String[] args) {
		FileWriter fw = null;
		
		try {
			fw = new FileWriter("C:/java/unicode.txt");
			for(int c = 0; c <= 50000; c++) {
				fw.write(c);
			}
			fw.close();
		} catch (IOException e) {
			System.out.println(e.getMessage());
			System.out.println("文件写入错误");
			System.exit(-1);
		}
	}
}


原文地址:https://www.cnblogs.com/wjchang/p/3671703.html