如何使用Jackson csv ma​​pper读取tsv文件?

时间:2017-10-24 19:55:19

标签: csv jackson jackson-dataformat-csv

我使用Jackson CSV lib来读取CSV文件。

我们获得了流媒体示例from the documentation

apply plugin: 'com.android.application'
repositories {
    maven { url 'https://maven.google.com' }
}
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId "bb.hoppingbird"
        minSdkVersion 14
        targetSdkVersion 26
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.google.android.gms:play-services:11.4.2'
}

这适用于CSV文件。但是我无法看到如何配置它以使用制表符而不是逗号作为字段分隔符,以便读取TSV文件。我可以找到列分隔符relates to the CsvSchema class的唯一配置,但没有架构,因为我们不知道文件中有多少列。

1 个答案:

答案 0 :(得分:1)

使用它:

CsvSchema  schema = mapper.schemaFor(String[].class).withColumnSeparator('\t');
ObjectReader reader = mapper.readerFor(String[].class).with(schema);