日期:2014-05-20 浏览次数:20727 次
public static void main(String[] args) { int a = 0; FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream("F:/hljk/HelloWorld.java"); out = new FileOutputStream("D:/java/HW.java"); while ((a = in.read()) != -1) { out.write(a); } } catch (FileNotFoundException e1) { System.out.println("此文件不存在"); System.exit(-1); } catch (IOException e2) { System.out.println("复制失败"); System.exit(-1); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } System.out.println("复制成功"); }
------解决方案--------------------
多看看别人写的代码,多领会一下,然后自己写代码的时候注意一下,就能解决好多问题
------解决方案--------------------