zl程序教程

您现在的位置是:首页 >  其他

当前栏目

复制文件详解编程语言

文件编程语言 详解 复制
2023-06-13 09:11:48 时间
 public static void copyTo(String srcName, String targetName) throws IOException { 

 File file = new File(srcName); 

 if (file.exists()) { 

 BufferedInputStream inBuff = null; 

 BufferedOutputStream outBuff = null; 

 try { 

 // 新建文件输入流并对它进行缓冲 

 inBuff = new BufferedInputStream(new FileInputStream(srcName)); 

 // 新建文件输出流并对它进行缓冲 

 outBuff = new BufferedOutputStream(new FileOutputStream(targetName)); 

 // 缓冲数组 

 byte[] b = new byte[1024 * 5]; 

 int len; 

 while ((len = inBuff.read(b)) != -1) { 

 outBuff.write(b, 0, len); 

 // 刷新此缓冲的输出流 

 outBuff.flush(); 

 } finally { 

 // 关闭流 

 if (inBuff != null) 

 inBuff.close(); 

 if (outBuff != null) 

 outBuff.close(); 

 }

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/17860.html

cjava