JSP复制整个文件夹的方法
来源:互联网 发布:msp430编程 编辑:程序博客网 时间:2024/04/30 05:03
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
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
- JSP复制整个文件夹的方法
- [转]PHP复制整个文件夹的FUNCTION
- C#复制整个文件夹
- JAVA 复制整个文件夹
- linux整个文件夹复制
- 复制整个文件夹下的文件(无限递归复制子文件夹)
- 如何复制、删除整个文件夹?
- vs导入整个文件夹的方法
- 文件夹复制和删除整个文件夹
- 一个拷贝整个文件夹(包括子文件夹)的方法
- 一个拷贝整个文件夹(包括子文件夹)的方法
- 一个拷贝整个文件夹(包括子文件夹)的方法
- 一个拷贝整个文件夹(包括子文件夹)的方法
- 递归的方法复制文件夹
- C#复制文件夹,删除文件夹的方法
- C#复制文件夹,删除文件夹的方法
- 复制文件夹所有内容 和 删除整个文件夹的2个函数(原创)
- 复制文件夹所有内容 和 删除整个文件夹的2个函数
- 为光驱添加“关闭”命令
- C++高级讨论会(一)
- 4月《男人装》读后感
- 贴图不说话
- 停电!
- JSP复制整个文件夹的方法
- 第七章第19题关键代码
- 第七章20题关键代码
- 第七章26题关键代码
- 迟到的累
- 很有创意的网站
- 铭记与遗忘
- 升级好了么?
- powerbuilder 9.0+下载 (内含补丁 build 7096)