档案系统文件挂接简单处理思路

档案系统文件挂接

  1. 拷贝文件到 FTP 服务器上
  2. 批量获取文件信息
  3. 分析表关系,插值
  4. 总结

拷贝文件到 FTP 服务器上

假设文件保存路径为 D:档案文件

批量获取文件信息

提取文件信息保存到txt中.bat

@ECHO OFF
dir D:档案文件*.pdf /s/b | find "[部分匹配内容]" > fileinfo.txt

参数描述 (具体描述可以在命令行中使用 help dir)
/s : 显示指定目录和所有子目录中的文件
/b : 不显示标题等信息

分析表关系,插值

  1. 分析存储文件相关的表关系
  2. 读 txt 文件,按行进行处理
    // 编码方式,根据实际需要进行更改
    private static final String ENCODING = "GB18030";

   /**
     * 获取文件的行
     *
     * @param fileName 文件名称
     * @return void
     */
    public static void getContentByLine(String fileName) {
        InputStreamReader read = null;
        BufferedReader bufferedReader = null;
        try {
            String configPath = new File(fileName).getPath();
            File file = new File(configPath);
            // 判断文件是否存在
            if (file.isFile() && file.exists()) { 
                read = new InputStreamReader(new FileInputStream(file), ENCODING);
                bufferedReader = new BufferedReader(read);
                String lineTxt;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    try {
                        if (lineTxt.length() == 0) {
                            continue;
                        }

                        /**
                         * TODO 获取到行,进行处理
                         */
                                        
                    } catch (Exception e) {
                        // TODO 出错了,跳过当前行,并记录错误信息
                        e.printStackTrace();
                        continue;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (read != null) {
                    read.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

总结

文件量多的话,会生成比较大的 txt 文件,导致打开的时候很慢。推荐使用 TXTkiller 进行分割,然后可以考虑使用多线程处理。有更好的处理思路欢迎评论。

原文地址:https://www.cnblogs.com/sethxiong/p/14345477.html