接下来我就将我的方法演示给一些初学者,希望能够帮助你们!
/*
* CopyRight by http://www.designac.org
*/
package copyfile;
import java.io.*;
/**
* @author Administrator
*
* Class Function:
*/
public class copyDirectory {
public static void main(String args[]) throws IOException {
String url1="C:/Downloads/kele";
String url2="d:/java/copyfile/copy";
(new File(url2)).mkdirs();
File[] file=(new File(url1)).listFiles();
for(int i=0;i
FileInputStream input=new FileInputStream(file[i]);
FileOutputStream output=new FileOutputStream(url2+"/"+file[i].getName());
byte[] b=new byte[1024*5];
int len;
while((len=input.read(b))!=-1){
output.write(b,0,len);
}
output.flush();
output.close();
input.close();
}
if(file[i].isDirectory()){
copyDirectiory(url2+"/"+file[i].getName(),url1+"/"+file[i].getName());
}
}
}
public static void copyDirectiory(String file1,String file2) throws IOException{
(new File(file1)).mkdirs();
File[] file=(new File(file2)).listFiles();
for(int i=0;i
FileInputStream input=new FileInputStream(file[i]);
FileOutputStream output=new FileOutputStream(file1+"/"+file[i].getName());
byte[] b=new byte[1024*5];
int len;
while((len=input.read(b))!=-1){
output.write(b,0,len);
}
output.flush();
output.close();
input.close();
}
if(file[i].isDirectory()){
copyDirectiory(file1+"/"+file[i].getName(),file2+"/"+file[i].getName());
}
}
}
}
Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd
标签: