- FileReader 字符输入流
@Test public void test2(){ File file = new File("hello.txt"); FileReader fr = null; try { fr = new FileReader(file); char[] cbuf = new char[5]; //返回读取的长度 int len; while ((len = fr.read(cbuf)) != -1){ String str = new String(cbuf, 0, len); System.out.print(str); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { if (fr != null){ try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } } }