如何实现文件夹对文件夹的拷贝呢?如果文件夹里还有文件夹怎么办呢?
接下来我就将我的方法演示给一些初学者希望能够帮助你们!
/*
* CopyRight by
*/
package copyfile;
import javaio*;
/**
* @author Administrator
*
* Class Function:
*/
public class copyDirectory {
public static void main(String args[]) throws IOException {
String url=C:/Downloads/kele;
String url=d:/java/copyfile/copy;
(new File(url))mkdirs();
File[] file=(new File(url))listFiles();
for(int i=;i<filelength;i++){
if(file[i]isFile()){
FileInputStream input=new FileInputStream(file[i]);
FileOutputStream output=new FileOutputStream(url+/+file[i]getName());
byte[] b=new byte[*];
int len;
while((len=inputread(b))!=){
outputwrite(blen);
}
outputflush();
outputclose();
inputclose();
}
if(file[i]isDirectory()){
copyDirectiory(url+/+file[i]getName()url+/+file[i]getName());
}
}
}
public static void copyDirectiory(String fileString file) throws IOException{
(new File(file))mkdirs();
File[] file=(new File(file))listFiles();
for(int i=;i<filelength;i++){
if(file[i]isFile()){
FileInputStream input=new FileInputStream(file[i]);
FileOutputStream output=new FileOutputStream(file+/+file[i]getName());
byte[] b=new byte[*];
int len;
while((len=inputread(b))!=){
outputwrite(blen);
}
outputflush();
outputclose();
inputclose();
}
if(file[i]isDirectory()){
copyDirectiory(file+/+file[i]getName()file+/+file[i]getName());
}
}
}
}