风故故,也依依

Stand still in the wind.

导航

用FileReader从文本读内容

import java.io.*;

public class FileReadTest
{
public static void main(String[] args)
{
   FileReadTest t = new FileReadTest();
   t.readMyFile();
}
void readMyFile()
{
   String temp = null;
   int count = 0;
   try
   {
    FileReader fr = new FileReader("mydata.txt");
    BufferedReader br = new BufferedReader(fr);
    temp = new String();
    while((temp = br.readLine()) != null)
    {
     count++;
     System.out.println(count + ":" + temp);
    }
    br.close();
    fr.close();
   }
   catch(IOException e)
   {
    System.out.println("OH,got an IOException error!");
    e.printStackTrace();
   }
}
}

posted on 2007-05-28 00:32  jadmin  阅读(164)  评论(0)    收藏  举报