JavaIO流中实现文件复制
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class FileCopy { public static void main(String[] args) { FileInputStream fis = null; FileOutputStream fos = null; try { fis=new FileInputStream("D:\\test.doc"); fos = new FileOutputStream("D:\\testfile\\test.doc"); byte[] bytes = new byte[1024]; int redCount=0; while((redCount=fis.read(bytes)) != -1){ fos.write(bytes,0,redCount); } fos.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
本文来自博客园,作者:guoyuxin3,转载请注明原文链接:https://www.cnblogs.com/guoyuxin3/p/15071865.html

浙公网安备 33010602011771号