2018-05-08|2018-05-08 IO 流复制

【2018-05-08|2018-05-08 IO 流复制】···swift

public class Copy { public static void main(String[] args) { long s=System.currentTimeMillis(); FileOutputStream fos=null; FileInputStream fis=null; try { fos=new FileOutputStream("E:\\java\\a.txt"); fis=new FileInputStream("D:\\a.txt"); int len=0; byte[] b=new byte[1024]; while((len=fis.read())!=-1) { System.out.println(new String(b,0,len)); fos.write(b,0,len); } } catch (IOException e) { // TODO: handle exception e.printStackTrace(); throw new RuntimeException("文件复制失败"); }finally{ try { if(fos!=null) fos.close(); } catch (IOException e) { throw new RuntimeException("关闭资源失败"); }finally { try { if(fis!=null) fis.close(); } catch (IOException e) { throw new RuntimeException("关闭资源失败"); } } } long m=System.currentTimeMillis(); System.out.println(m-s); }

}

    推荐阅读