- import java.io.*;
- class FileReaderDemo2
- {
- public static void main(String[] args)
- {
- FileReader fr = null;
- char[] ch = new char[1024];
- int num = 0;
- try
- {
- fr = new FileReader("demo3.txt");
- while((num = fr.read(ch))!=-1)
- {
- System.out.println(num+"*****"+(new String(ch,0,num)));
- }
- }
- catch (IOException e)
- {
- System.out.println(e.toString());
- }
- finally
- {
- try
- {
- if(fr!=null)
- fr.close();
- }
- catch (IOException e)
- {
- System.out.println(e.toString());
- }
- }
- }
- }
复制代码 |
|