Search code examples
kotlinfile

Read Csv format file and convert to txt extension with tsv format


I'm trying to read csv format file line-by-line like below to convert origin file to target file.

csvReader().open("test.csv") {
    readNext()
}

While reaidng csv file, I want to create txt file with tsv format like below.

id  title   price_pc    shipping    rental_info
uniqueID    producttitle    1434000 0   23900^60


  1. When reading csv file line-by-line, is it able to create file and add line-by-line in tsv format? I'm not sure what library should I use for this.
  2. If the original file size is more than 20MB, are there other ways to handle this file more efficiently?

Solution

  • I've previously used Kotlin DataFrame which can solve your problem. You can find more information here

    This is a sample code for you need:

    fun main() {
        DataFrame.read("test.csv").writeCSV("test.tsv", CSVFormat.TDF)
    }