为什么我没有转化成String也可以正常读取???
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public static void iprByCharArray(File file) throws IOException { if (!file.exists()){ throw new IllegalArgumentException( "文件不存在" ); } if (!file.isFile()){ throw new IllegalArgumentException( "不是文件" ); } FileInputStream in= new FileInputStream(file); InputStreamReader ipr= new InputStreamReader(in); int c; char [] chars= new char [ 2 * 1024 ]; System.out.println( "字符流批量读取" ); while ((c=ipr.read(chars, 0 ,chars.length))!=(- 1 )){ System.out.print(chars); } } |