public static void main(String[] args) {
// TODO Auto-generated method stub FileReader fr = null; FileWriter fw = null; try { fr = new FileReader("demo.txt"); fw = new FileWriter("cope.txt"); int ch = 0;//每次只读一个字节
while ((ch = fr.read()) != -1) {
fw.write(ch); } } catch (Exception e) { // TODO: handle exception throw new RuntimeException("复制失败"); }finally { if (fr != null) { try { fr.close(); } catch (Exception e2) { // TODO: handle exception } } if (fw != null) { try { fw.close(); } catch (Exception e2) { // TODO: handle exception } } } }