InputStreamReader的用法示例

来源:互联网 发布:反身性理论 知乎 编辑:程序博客网 时间:2024/05/21 09:06

//与FileInputStream几乎一样,唯一不同的是他可以读取16为的Unicode字符,如汉字等。
import java.io.*;

public class InputStreamReader Demo
{
 public static void main(String[] args)throws IOException
 {
  try
  {
   int b;
   InputStreamReader isr = new InputStreamReader (new FileInputStream (new File ("D://testfile//input.log")));
   System.out.println ("The content of text is:");
   while ((b = isr.read()) != -1)//顺序读取文件text里的内容并赋值给整型变量b,直到文件结束为止。
   {
    System.out.print((char)b);
   }
   isr.close();
  }
  catch(FileNotFoundException e)
  {
   System.out.println(e);
  }
  catch(IOException e)
  {
   System.out.println(e);
  }
  catch(Exception e)
  {
   System.out.println(e);
  }
 }
}

 
原创粉丝点击