//与FileInputStream几乎一样,唯一不同的是他可以读取16为的Unicode字符,如汉字等。import java.io.*; public class InputStreamReaderDemo{ 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); } }}

评论