JSP复制整个文件夹的方法

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class CopyFile {
private static String sourcepath;

private static String destpath;

//处理参数
private void processArgs(String[] args) {
if (args.length != 2) {
System.out.println("请输入两个文件目录……");
System.exit(1);
}//end if
else {
sourcepath = args[0];
destpath = args[1];
}//end else
}//end processArgs

//拷贝文件
private void copyFile(String source, String dest) {
try {
File in = new File(source);
File out = new File(dest);
FileInputStream inFile = new FileInputStream(in);
FileOutputStream outFile = new FileOutputStream(out);
byte[] buffer = new byte[1024];
int i = 0;
while ((i = inFile.read(buffer)) != -1) {
outFile.write(buffer, 0, i);
}//end while
inFile.close();
outFile.close();
}//end try
catch (Exception e) {

}//end catch
}//end copyFile

//处理目录
public void copyDict(String source, String dest) {
String source1;
String dest1;

File[] file = (new File(source)).listFiles();
for (int i = 0; i < file.length; i++)
if (file .isFile()) {
source1 = source + "/" + file.getName();
dest1 = dest + "/" + file.getName();
copyFile(source1, dest1);
}//end if
for (int i = 0; i < file.length; i++)
if (file.isDirectory()) {
source1 = source + "/" + file.getName();
dest1 = dest + "/" + file.getName();
File dest2 = new File(dest1);
dest2.mkdir();
copyDict(source1, dest1);
}//end if
}//end copyDict

public static void main(String args[]) {
CopyFile copyFile = new CopyFile();
copyFile.processArgs(args);
copyFile.copyDict(sourcepath, destpath);
}
}//end CopyFile
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值