IO字符源FileReader读取数据

IO字符流FileReader读取数据
import java.io.*;
class  FileReaderDemo
{
	public static void main(String[] args) throws IOException
	{
		//建立一个字符读取流对象,与指定文件相关联。
		FileReader fr = new FileReader("demo.txt");

		//创建一个字符数组。为了将从硬盘上读取的每一个字符存入数组中。
		char[] arr = new char[1024];
		int num = 0;
		while((num = fr.read(arr))!=-1)
		{
			System.out.println(new String(arr,0,num));
		}

		/*
		int x = fr.read(arr);
		
		System.out.println(new String(arr,0,x)+","+x);

		int y = fr.read(arr);

		System.out.println(new String(arr,0,y)+","+y);

		int z = fr.read(arr);
		System.out.println(z);
		*/
		fr.close();


	}
}

 

import java.io.*;
class  FileReaderDemo2
{
	public static void main(String[] args) throws IOException
	{
		FileReader fr = new FileReader("demo.txt");
		
		int ch = 0;

		while((ch=fr.read())!=-1)
		{
			System.out.print((char)ch);
		}

		/*
		int ch = fr.read();
		System.out.println(ch);
		int ch1 = fr.read();
		System.out.println(ch1);
		*/
		fr.close();


	}
}