【问题标题】:Skip comments & surroundingSpacesNeedQuotes with supercsv 2.2.0使用 supercsv 2.2.0 跳过评论和环绕SpacesNeedQuotes
【发布时间】:2014-10-09 08:06:17
【问题描述】:

我会忽略以 '#' 字符开头的 cmets 和带引号的周围空格,但使用 opencsv 2.2.0 不起作用。 我搜索了 supercsv 的源代码,但它从未在代码中使用过跳过注释功能首选项。 你能帮帮我吗?

提前致谢。

【问题讨论】:

    标签: supercsv


    【解决方案1】:

    正如网站上的documentation 所示,您必须创建一个自定义CsvPreference 并将其传递给您的CsvReader 的构造函数。例如

    // create the custom preference
    CsvPreference skipCommentsPreference = new CsvPreference.Builder(
        CsvPreference.STANDARD_PREFERENCE)
       .skipComments(new CommentStartsWith("#").build();
    
    // create your reader with the preference
    ICsvBeanReader beanReader = new CsvBeanReader(
        new FileReader("my.csv"), skipCommentsPreference);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-26
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 2021-02-09
      相关资源
      最近更新 更多