解析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");
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一個滾燙的愛字, 暖在手心,暖著暖著, 就暖成了一朵晶瑩的雪花, 蓬絨絨地溶入 刻骨的一種心銘里 流淌心靈與肌體的呼吸
    詩與遠(yuǎn)方工作室閱讀 275評論 0 0
  • 這是一個從琢磨我自己的故事想到的故事。很久以前讀了朱利安·巴恩斯的《終結(jié)的感覺》,講的是個人與回憶,或者說個人講述...
    Cheburashika閱讀 380評論 0 0

友情鏈接更多精彩內(nèi)容