A cop file class that automatically increments the directory and files

Source: Internet
Author: User
Tags gettext mkdir
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}}}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.