public class TestIO01 {public static void main(String[] args) {copy("D:/aaa.txt","D:/B.txt");//把前者文件的内容拷贝到后者文件中qu } public static void copy(String srcfile,String destpath) {File file=new File(srcfile);File file1=new File(destpath);InputStream is=null;OutputStream os=null;try { is=new FileInputStream(file); os=new FileOutputStream(file1);byte[] car=new byte[3];int temp;int len;while((len=is.read(car))!=-1){ os.write(car,0, len);String str=new String(car,0,len); } os.flush(); } catch (FileNotFoundException fileNotFoundException) { fileNotFoundException.printStackTrace(); } catch (IOException ioException) { ioException.printStackTrace(); }finally{try{if(is!=null){ is.close(); } }catch (IOException ioException){ ioException.printStackTrace(); }try{if(is!=null){ is.close(); } }catch (IOException ioException){ ioException.printStackTrace(); } } } }
本文参考链接:https://www.yisu.com/zixun/541292.html