- import java.io.*;
- class FileReaderDemo
- {
- public static void main(String[] args)
- {
- FileReader fr=null;
- try
- {
- fr=new FileReader("demo.txt");
- /*for(int num=fr.read();num>0;num= fr.read())
- {
- System.out.println("num="+(char)num);
- }
- */int num=0;
- while((fr.read())>0)
- {
- num=fr.read();
- System.out.println("num="+(char)num);
- }
- }
- catch (IOException i)
- {
- throw new RuntimeException("文件未找到");
- }
- finally
- {
- try
- {
- if(fr!=null)
- fr.close();
- }
- catch (IOException i)
- {
- throw new RuntimeException("文件未找到");
- }
- }
-
- }
- }
复制代码
|
|