/*
* 程序头部注释开始
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:IO操作 通过字符数组进行读取
* 作 者:薛广晨
* 完成日期:2011 年 10 月 04 日
* 版 本号:x1.0
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
import java.io.*;
class FileReaderTest2
{
public static void main(String[] args)
{
//定义一个字符数组。用于存储读到字符。
//该read(char[])返回的是读到字符个数。
char [] buf = new char[1024];
FileReader fr = null;
try
{
fr = new FileReader("Test.txt");
int num = 0;
while((num = fr.read(buf)) != -1)
{
System.out.println(new String(buf, 0, num));
}
}
catch (IOException e)
{
System.out.println("catch:" + e.toString());
}
finally
{
try
{
if(fr != null)
fr.close();
}
catch (IOException e)
{
System.out.println("catch:" + e.toString());
}
}
}
}
运行结果: