Univocity解析器在Java中,根据特定列解析CSV。

huangapple 未分类评论46阅读模式
英文:

Univocity Parser in Java, parsing the CSV based on a particular column

问题

我对Univocity解析器还不太了解,我想知道是否有任何方法可以根据特定列的值解析csv文件,考虑到我想解析的CSV文件的大小,我希望根据日期属性来解析它。(例如:如果日期是2020年1月1日,那么只解析那些日期值与给定值匹配的行,即2020年1月1日)

如果您能就此问题提供任何见解,我将不胜感激。

我真的很感谢如果有人能够为我提供有关所述问题的任何见解。

谢谢,
Ria

英文:

I am quite new to Univocity Parser and I want to know if there is any way I can parse the csv file based on a value of particular column, considering the size of CSV I want to parse it based on a date attribute.(For Ex: if date is 1/1/2020 then parse only those rows that has date value matches with given value, i.e., 1/1/2020)

I will really appreciate if you can provide me any insight regarding this.

I really appreciate if someone can provide me any insight with the stated problem.

Thankyou,
Ria

答案1

得分: 0

parser.beginParsing(new FileReader(new File("abc.csv")));
int count = 0;
String[] row;
List<AttributesField> beanss = new ArrayList<>();
while ((row = parser.parseNext()) != null) {
    AttributesField af = rowProcessor.createBean(row, parser.getContext());
    row = af.getCommitted_at().split(" ");
    if (row[0].compareTo("2013-11-13") <= 0) {
        beanss.add(af);
    }
}
英文:
parser.beginParsing(new FileReader(new File(&quot;abc.csv&quot;)));
        int count=0;
        String[] row;
        List&lt;AttributesField&gt; beanss= new ArrayList&lt;&gt;();
        while((row=parser.parseNext())!= null)
        {
            AttributesField af=rowProcessor.createBean(row, parser.getContext());
            row=af.getCommitted_at().split(&quot; &quot;);
            if(row[0].compareTo(&quot;2013-11-13&quot;) &lt;=0)  //Hardcode the date: return a.compareTo(d) * d.compareTo(b) &gt; 0;
            {
                beanss.add(af);
            }
        }

答案2

得分: 0

Just filter and skip rows you don't need.
This is very easy since univocity provides iterative approach.

英文:

Just filter and skip rows you don't need.
This is very easy since univocity provides iterative approach.

huangapple
  • 本文由 发表于 2020年4月4日 06:33:24
  • 转载请务必保留本文链接:https://java.coder-hub.com/61021401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定