解析OUT文件

public void parseOUT() throws IOException {
    long startTime = System.currentTimeMillis();

        final String filename = "D:\\TEMCONH.OUT";

        File file = new File(filename);
        List<String> list = new ArrayList<String>();

        if (file.exists() && file.isFile()) {
            InputStreamReader read = new InputStreamReader(new FileInputStream(file));
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;
            int count = 0;
            while ((lineTxt = bufferedReader.readLine()) != null) {
                count++;
                if (count > 4) {
                    list.add(lineTxt);
                }
            }
            bufferedReader.close();
            read.close();
        }
        int[] cols = new int[list.size()];
        int[] rows = new int[list.size()];
        double[] salis = new double[list.size()];

        for (int i = 0; i < list.size(); ++i) {
            String[] strs = list.get(i).split("\\s+");
            if (strs.length >= 4) {
                cols[i] = Integer.parseInt(strs[1]);
                rows[i] = Integer.parseInt(strs[2]);
                salis[i] = Double.parseDouble(strs[3]);
            }
        }
        long endTime = System.currentTimeMillis();
        for (int i = 0; i < salis.length; i++) {
            System.out.println(cols[i]);
            System.out.println(rows[i]);
            System.out.println(salis[i]);
            System.out.println();
        }
        System.out.println("共  " + salis.length + " 条, 耗时 " + (endTime - startTime) + " ms");
}

更新算法:

public void parseOUT() throws IOException {

        long startTime = System.currentTimeMillis();

        final String filename = "D:\\TEMCONH.OUT";

        final Integer COUNT = 463*36;
        
        File file = new File(filename);

        int[] cols = new int[COUNT];
        int[] rows = new int[COUNT];
        double[] salis = new double[COUNT];
        
        if (file.exists() && file.isFile()) {
            InputStreamReader read = new InputStreamReader(new FileInputStream(file));
            BufferedReader bufferedReader = new BufferedReader(read);
            String lineTxt = null;
            int allCount = 0;
            int itemCount = 0;
            while ((lineTxt = bufferedReader.readLine()) != null) {
                allCount++;
                if (allCount > 4) {
                    String [] strs = lineTxt.split("\\s+");
                    if (strs.length >= 4) {
                        cols[itemCount] = Integer.parseInt(strs[1]);
                        rows[itemCount] = Integer.parseInt(strs[2]);
                        salis[itemCount] = Double.parseDouble(strs[3]);
                        itemCount++;
                    }
                }
            }
            bufferedReader.close();
            read.close();
        }
        
        long endTime = System.currentTimeMillis();
//      for (int i = 0; i < salis.length; i++) {
//          System.out.println(cols[i]);
//          System.out.println(rows[i]);
//          System.out.println(salis[i]);
//          System.out.println();
//      }
        System.out.println("共  " + salis.length + " 条, 耗时 " + (endTime - startTime) + " ms");
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 一个滚烫的爱字, 暖在手心,暖着暖着, 就暖成了一朵晶莹的雪花, 蓬绒绒地溶入 刻骨的一种心铭里 流淌心灵与肌体的呼吸
    诗与远方工作室阅读 1,693评论 0 0
  • 这是一个从琢磨我自己的故事想到的故事。很久以前读了朱利安·巴恩斯的《终结的感觉》,讲的是个人与回忆,或者说个人讲述...
    Cheburashika阅读 2,720评论 0 0

友情链接更多精彩内容