package Com.hudong.util.orther;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.IOException;
Import java.util.List;
Import Org.apache.commons.io.FileUtils;
Import Org.apache.commons.logging.Log;
Import Org.apache.commons.logging.LogFactory;
Import org.dom4j.DocumentException;
Import org.dom4j.Element;
Import Org.dom4j.io.SAXReader; /** * Traverse File * * @Title: Ergodicfile.java * @Copyright: Copyright (c) * @Description: <br> * <br> * @Company: * * *
* @Created on 2013-8-15 a.m. 9:41:20 * @author Yang/public class Judgecopyergodicfile {private static int k = 1, M
= 1;
Private final static Log logger = Logfactory.getlog (Judgecopyergodicfile.class);
public static void Main (string[] args) throws IOException {File File = new file ("e:/company data/39 NET Data/FINAL XML data");
Ergodicfolder (file);
The public static void Ergodicfolder (file file) throws IOException {file[] filelist = File.listfiles ();
for (int i = 0; i < filelist.length i++) {//Traverse file if (Filelist[i].isfile ()) {//judgment is file
Here is necessary, be sure to hibernate, otherwise it will cause the file to overwrite try {thread.sleep (1l);
catch (Interruptedexception e) {e.printstacktrace (); } if ("Summary.xml". Equals (Filelist[i].getname ()) {try {Lis t<element> root = new Saxreader (). Read (New FileInputStream (FilelIst[i])). Getrootelement (). elements ();
for (Element e:root) {String content = e.element ("Summary_content"). Gettexttrim (); if (! "".
Equals (content)) {file Summaryfile = new file ("e:/yiyuan/summary/" + K + "/");
Summaryfile.mkdir ();
Fileutils.copyfile (Filelist[i], new File (Summaryfile.getabsolutepath () + "/" + system.currenttimemillis () + ". xml"));
m++;
if (M > 1000) {k++;
m = 1;
} else {Logger.info (e.element ("Doc_title"). GetText ());
System.out.println (E.element ("Doc_title"). GetText ());
}
} catch (Documentexception E1) {e1.printstacktrace (); ' Else if ' (' Content.xml '. Equals (Filelist[i].getname ()) {File contentfile = new Fil
E ("e:/yiyuan/docinfo/" + K + "/" + System.currenttimemillis ());
Contentfile.mkdir ();
File Desfile = new file (Contentfile.getabsolutepath () + "/docinfo.xml");
Fileutils.copyfile (Filelist[i], desfile);
m++;
if (M > 1000) {k++;
m = 1; }} else if (Filelist[i].isdirectory ()) {//Judgment is directory Ergodicfolder (filelist[i) );
Recursive}}}