现在的位置: 首页 > 综合 > 正文

Java输入输出(4)–转换流

2018年04月06日 ⁄ 综合 ⁄ 共 564字 ⁄ 字号 评论关闭

1.将字节流转换成字符流

public class KeyinTest

{

   public static void main(String[] args)

   {

      BufferedReader  br = null;

     try

     {

      InputStreamReader  reader = new InputStreamReader(System.in);

      br  = new BufferedReader(reader);

      String buffer = null;

      while((buffer = br.readLine())!=null)

      {

          if(buffer.equals("exit"))

         {

           System.exit(1);

         }

       System.out.println("输入内容为:"+buffer);

     }

     }

   catch(IOException  ioe)

   {

      ioe.printStackTrace();

   }

  finally

  {

    try

    {

    br.close();

    }

   catch(IOException ioe)

   {

      ioe.printStackTrace();

   }

  }

   }

}

抱歉!评论已关闭.