io流複製檔案的方法
阿新 • • 發佈:2018-12-18
public void copyFile(String fromFile,String toFile){ FileOutputStream fos = null; FileInputStream fis = null; try { fos = new FileOutputStream(toFile); fis = new FileInputStream(fromFile); byte[] bs = new byte[1024]; int len = 0; while((len=fis.read(bs))>0){ fos.write(bs,0,len); } } catch (IOException e) { e.printStackTrace(); }finally { try { if(fis!=null){ fis.close(); } if(fos!=null){ fos.close(); } } catch (IOException e) { e.printStackTrace(); } }