zoukankan      html  css  js  c++  java
  • 一个自动递增生成目录和文件的cop文件类

    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;
    
    /**
     * 遍历文件
     * 
     * @Title: ErgodicFile.java
     * @Copyright: Copyright (c) 2005
     * @Description: <br>
     * <br>
     * @Company: ***
     * @Created on 2013-8-15 上午9:41:20
     * @author 杨凯
     */
    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:/公司资料/39网资料/最终xml数据");
            ergodicFolder(file);
        }
    
        public static void ergodicFolder(File file) throws IOException {
    
            File[] fileList = file.listFiles();
    
            for (int i = 0; i < fileList.length; i++) { // 遍历文件
                if (fileList[i].isFile()) { // 判断是文件
                    // 这里是必须的,一定要休眠,否则会导致文件的覆盖
                    try {
                        Thread.sleep(1l);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    if ("summary.xml".equals(fileList[i].getName())) {
                        try {
                            List<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 File("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()) { // 判断是目录
                    ergodicFolder(fileList[i]); // 递归
                }
            }
        }
    }
    
    


     

  • 相关阅读:
    macbook 无声音解决方案
    webapck dev server代理请求 json截断问题
    百度卫星地图开启
    服务器 nginx配置 防止其他域名绑定自己的服务器
    记一次nginx php配置的心路历程
    遇到npm报错read ECONNRESET怎么办
    运行svn tortoiseSvn cleanup 命令失败的解决办法
    svn add 命令 递归目录下所有文件
    m4出现Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib."
    Ubuntu下安装GCC,mpc、mpfr、gmp
  • 原文地址:https://www.cnblogs.com/yangkai-cn/p/4016800.html
Copyright © 2011-2022 走看看