18 BufferedReader使用方法

时间:2023-03-08 16:03:01
18 BufferedReader使用方法

生成BufferedReader对象的方法:

  BufferedReader in=new BufferedReader(new FileReader("foo.in"));

import java.io*;

class Test

{
  public static void main(String args[])

  {

    FileReader fileReader=null;

    BufferedReader bufferedReader=null;

    try

    {

      fileReader=new FileReader("e:/src/users.txt");

      bufferedReader=new BufferedReader(fileReader);

      String line=null;

      while(true)

      {

        line=bufferedReader.readline();

        if(line==null)break;

        System.out.println(line);

      }

    }

    catch(Exception e)

    {

      System.out.println(e);

    }

    finally

    {

      try{

      }

      catch(Exception e)

      {

        System.out.println(e);

      }

    }

  }

}