{"id":13801586,"url":"https://github.com/tototoshi/scala-csv","last_synced_at":"2025-05-14T13:07:45.075Z","repository":{"id":2670456,"uuid":"3662124","full_name":"tototoshi/scala-csv","owner":"tototoshi","description":"CSV Reader/Writer for Scala","archived":false,"fork":false,"pushed_at":"2025-02-03T07:59:48.000Z","size":6209,"stargazers_count":698,"open_issues_count":30,"forks_count":143,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-11T06:11:23.460Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tototoshi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-03-08T17:02:19.000Z","updated_at":"2025-03-23T15:56:20.000Z","dependencies_parsed_at":"2023-01-13T12:00:51.983Z","dependency_job_id":"ff918431-c876-4460-8fe9-0c6790db59d1","html_url":"https://github.com/tototoshi/scala-csv","commit_stats":{"total_commits":478,"total_committers":34,"mean_commits":"14.058823529411764","dds":0.698744769874477,"last_synced_commit":"9620e1d193265415c27b6f98cdca852c3d49c689"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tototoshi%2Fscala-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tototoshi%2Fscala-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tototoshi%2Fscala-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tototoshi%2Fscala-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tototoshi","download_url":"https://codeload.github.com/tototoshi/scala-csv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149958,"owners_count":22022851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:24.681Z","updated_at":"2025-05-14T13:07:40.062Z","avatar_url":"https://github.com/tototoshi.png","language":"Scala","funding_links":[],"categories":["Table of Contents","CSV"],"sub_categories":["CSV"],"readme":"# scala-csv\n\n## build.sbt\n\n```scala\nlibraryDependencies += \"com.github.tototoshi\" %% \"scala-csv\" % \"2.0.0\"\n```\n\n## Example\n\n### import\n\n```scala\nscala\u003e import com.github.tototoshi.csv._\n```\n\n### Reading example\n\nsample.csv\n```\na,b,c\nd,e,f\n```\n\nYou can create CSVReader instance with CSVReader#open.\n\n```scala\nscala\u003e val reader = CSVReader.open(new File(\"sample.csv\"))\n```\n\n#### Reading all lines\n```scala\nscala\u003e val reader = CSVReader.open(new File(\"sample.csv\"))\nreader: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@36d0c6dd\n\nscala\u003e reader.all()\nres0: List[List[String]] = List(List(a, b, c), List(d, e, f))\n\nscala\u003e reader.close()\n```\n\n#### Using iterator\n```scala\nscala\u003e val reader = CSVReader.open(\"sample.csv\")\nreader: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@22d568da\n\nscala\u003e val it = reader.iterator\nit: Iterator[Seq[String]] = non-empty iterator\n\nscala\u003e it.next\nres0: Seq[String] = List(a, b, c)\n\nscala\u003e it.next\nres1: Seq[String] = List(d, e, f)\n\nscala\u003e it.next\njava.util.NoSuchElementException: next on empty iterator\n        at com.github.tototoshi.csv.CSVReader$$anon$1$$anonfun$next$1.apply(CSVReader.scala:55)\n        at com.github.tototoshi.csv.CSVReader$$anon$1$$anonfun$next$1.apply(CSVReader.scala:55)\n        at scala.Option.getOrElse(Option.scala:108)\n\nscala\u003e reader.close()\n```\n\n#### Reading all lines as Stream\n```scala\nscala\u003e val reader = CSVReader.open(new File(\"sample.csv\"))\nreader: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@7dae76b4\n\nscala\u003e reader.toStream\nres7: Stream[List[String]] = Stream(List(a, b, c), ?)\n```\n\n#### Reading one line at a time\n\nThere a two ways available. #foreach and #readNext.\n\n```scala\nscala\u003e val reader = CSVReader.open(new File(\"sample.csv\"))\nreader: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@4720a918\n\nscala\u003e reader.foreach(fields =\u003e println(fields))\nList(a, b, c)\nList(d, e, f)\n\nscala\u003e reader.close()\n```\n\n```scala\nscala\u003e val reader = CSVReader.open(new File(\"sample.csv\"))\nreader: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@4b545701\n\nscala\u003e reader.readNext()\nres3: Option[List[String]] = Some(List(a, b, c))\n\nscala\u003e reader.readNext()\nres4: Option[List[String]] = Some(List(d, e, f))\n\nscala\u003e reader.readNext()\nres5: Option[List[String]] = None\n\nscala\u003e reader.close()\n```\n\n#### Reading a csv file with column headers\n\nwith-headers.csv\n```\nFoo,Bar,Baz\na,b,c\nd,e,f\n```\n\n````scala\nscala\u003e val reader = CSVReader.open(new File(\"with-headers.csv\"))\nreader: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@1a64e307\n\nscala\u003e reader.allWithHeaders()\nres0: List[Map[String,String]] = List(Map(Foo -\u003e a, Bar -\u003e b, Baz -\u003e c), Map(Foo -\u003e d, Bar -\u003e e, Baz -\u003e f))\n````\n\n### Writing example\n\n#### Writing all lines with #writeAll\n\n```scala\nscala\u003e val f = new File(\"out.csv\")\n\nscala\u003e val writer = CSVWriter.open(f)\nwriter: com.github.tototoshi.csv.CSVWriter = com.github.tototoshi.csv.CSVWriter@783f77f1\n\nscala\u003e writer.writeAll(List(List(\"a\", \"b\", \"c\"), List(\"d\", \"e\", \"f\")))\n\nscala\u003e writer.close()\n```\n\n\n#### Writing one line at a time with #writeRow\n```scala\nscala\u003e val f = new File(\"out.csv\")\n\nscala\u003e val writer = CSVWriter.open(f)\nwriter: com.github.tototoshi.csv.CSVWriter = com.github.tototoshi.csv.CSVWriter@41ad4de1\n\nscala\u003e writer.writeRow(List(\"a\", \"b\", \"c\"))\n\nscala\u003e writer.writeRow(List(\"d\", \"e\", \"f\"))\n\nscala\u003e writer.close()\n```\n\n#### Appending lines to the file that already exists\nThe default behavior of CSVWriter#open is overwriting.\nTo append lines to the file that already exists, Set the append flag true.\n\n```scala\nscala\u003e val writer = CSVWriter.open(\"a.csv\", append = true)\nwriter: com.github.tototoshi.csv.CSVWriter = com.github.tototoshi.csv.CSVWriter@67a84246\n\nscala\u003e writer.writeRow(List(\"4\", \"5\", \"6\"))\n\nscala\u003e writer.close()\n```\n\n### Customizing the format\n\nCSVReader/Writer#open takes CSVFormat implicitly.\nDefine your own CSVFormat when you want to change the CSV's format.\n\n```scala\nscala\u003e :paste\n// Entering paste mode (ctrl-D to finish)\n\nimplicit object MyFormat extends DefaultCSVFormat {\n  override val delimiter = '#'\n}\nval w = CSVWriter.open(new java.io.OutputStreamWriter(System.out))\n\n// Exiting paste mode, now interpreting.\n\ndefined module MyFormat\nw: com.github.tototoshi.csv.CSVWriter = com.github.tototoshi.csv.CSVWriter@6cd66afa\n\nscala\u003e w.writeRow(List(1, 2, 3))\n\"1\"#\"2\"#\"3\"\n```\n### Changing the encoding\nBy default the UTF-8 is set. To change it, for example, to ISO-8859-1 you can set it in the CSVReader:\n```scala\nscala\u003e val reader = CSVReader.open(filepath, \"ISO-8859-1\")\nreader: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@6bcb69ba\n```\n\n## Dev\n\n```\n$ git clone https://github.com/tototoshi/scala-csv.git\n$ cd scala-csv\n$ sbt\n\u003e test\n```\n\n## License\n[Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftototoshi%2Fscala-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftototoshi%2Fscala-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftototoshi%2Fscala-csv/lists"}