有没有更快的方法在 Java 中使用 csv 阅读器?

问题描述

我需要打开更多部分的 csv 文件,每个部分包含 5,000 个样本,然后绘制它们。要在每次单击按钮时来回发送信号,我必须实例化一个新的阅读器,然后跳到我需要的点。我的信号很大,大约有 135,000 个样本,所以当我处理最后一个样本时, csvReader.skip() 方法非常慢。但是要回去我不能删除行,所以每次我的迭代器都需要重新实例化。我注意到跳过使用 for 循环?有没有更好的方法解决这个问题?这是我的代码

    public void updateSign(int segmento) {
    Log.d("segmento",Integer.toString(segmento));
    //check if I am in the signal length
    if (segmento>0 && (float)(segmento-1)<=(float)TOTAL/normaLen)
    {
        try {
            reader = new CSVReader(new FileReader(new File(patty)));
        } catch (FileNotFoundException e) {
            e.printstacktrace();
        }

        List<Integer> sign = new ArrayList<>();
        //this is the point of the signal where i finish
        int len = segmento * normaLen;
        //check if i am at the end of the signal
        if (len >= TOTAL) {
            len = TOTAL;
            segmento=0;
            avanti.setValue(false);
            System.out.println(avanti.getValue());
        } else {
            lines = TOTAL - len;

            avanti.setValue(true);
            System.out.println(avanti.getValue());
        }
        //the int to i need to skip
        int skipper = (segmento-1)*normaLen;
        try {
            System.out.println("pre skip");
            reader.skip(skipper);
            System.out.println("post skip");
        } catch (IOException e) {
            e.printstacktrace();
        }
        //my iterator
        it = reader.iterator();
        System.out.println("iteratore fatto");
        //loop to build my mini-signal to plot
        //having only 5,000 sample it is fast enaugh
        for (int i = skipper; i < len-1; i++) {

            if (i>=(segmento-1)*normaLen) {

                sign.add(Integer.parseInt(it.next()[0]));

            }
            else
            {

                it.next();
                System.out.println("non ha funzionato lo skip");
            }
        }
        System.out.println("ciclo for: too much fatica?");
        //set sign to be plotted by my fragment
        liveSign.setValue(sign);
    }
}

提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...