package com.hudong.test;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
public class ErgodicFile {
public static void main(String[] args) throws IOException {
File file = new File("E:\ershouok1");
// ergodicFile(file, 0);
ergodicFileFolder(file);
}
/**
* 生成文件
*
* @param file
* @param temp
* @return
* @throws IOException
*/
public static List<File> ergodicFile(File file, int temp) throws IOException {
List<File> list = new ArrayList<File>();
File[] fileList = file.listFiles();
for (int i = 0; i < fileList.length; i++) {
File docFile = new File("E:\39yiyuan\doc\" + temp + ".xml");
File summaryFile = new File("E:\39yiyuan\summary\" + temp + ".xml");
File contentFile = new File("E:\39yiyuan\content\" + temp + ".xml");
if (fileList[i].isFile()) { // 判断是文件
if ("doc.xml".equals(fileList[i].getName())) {
FileUtils.copyFile(fileList[i], docFile); //copy文件
} else if ("summary.xml".equals(fileList[i].getName())) {
FileUtils.copyFile(fileList[i], summaryFile);
} else if ("content.xml".equals(fileList[i].getName())) {
FileUtils.copyFile(fileList[i], contentFile);
}
} else if (fileList[i].isDirectory()) { // 判断是目录
ergodicFile(fileList[i], i); // 递归
}
}
return list;
}
/**
* 生成带文件夹的文件
*
* @param file
* @param temp
* @return
* @throws IOException
*/
public static List<File> ergodicFileFolder(File file) throws IOException {
List<File> list = new ArrayList<File>();
File[] fileList = file.listFiles();
for (int i = 0; i < fileList.length; i++) { //遍历文件
if (fileList[i].isFile()) { // 判断是文件
if ("doc.xml".equals(fileList[i].getName())) {
File docFile = new File("E:/yiyuan/doc/" + System.currentTimeMillis());
docFile.mkdir();
FileUtils.copyFile(fileList[i], new File(docFile.getAbsolutePath() + "/doc.xml"));
} else if ("summary.xml".equals(fileList[i].getName())) {
File contentFile = new File("E:/yiyuan/summary/" + System.currentTimeMillis());
contentFile.mkdir();
FileUtils.copyFile(fileList[i], new File(contentFile.getAbsolutePath() + "/summary.xml"));
} else if ("content.xml".equals(fileList[i].getName())) {
File summaryFile = new File("E:/yiyuan/content/" + System.currentTimeMillis());
summaryFile.mkdir();
FileUtils.copyFile(fileList[i], new File(summaryFile.getAbsolutePath() + "/content.xml"));
}
} else if (fileList[i].isDirectory()) { // 判断是目录
ergodicFileFolder(fileList[i]); // 递归
}
}
return list;
}
}