@Test public void test4(){ FileReader fr = null; FileWriter fw = null; try { fr = new FileReader("hello.txt"); fw = new FileWriter("hello1.txt"); char[] cbuf = new char[5]; int len; while ((len = fr.read(cbuf)) != -1){ fw.write(cbuf, 0, len); } } catch (IOException e) { e.printStackTrace(); }finally { if (fw != null){ try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } if (fr != null){ try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } } }