Giter VIP home page Giter VIP logo

fastcsv's Introduction

FastCSV

build Codacy Badge codecov javadoc Maven Central

FastCSV is an ultra-fast and dependency-free RFC 4180 compliant CSV library for Java.

Actively developed and maintained since 2015 its primary intended use cases are:

  • big data applications to read and write data on a massive scale
  • small data applications with the need for a lightweight library

Benchmark & Compatibility

A selected benchmark from the Java CSV library benchmark suite project:

Benchmark

While maintaining high performance, FastCSV is a strict RFC 4180 CSV writer but also able to read garbled CSV data (to some degree). See JavaCsvComparison for details.

Features

API

  • Ultra fast
  • Small footprint
  • Zero runtime dependencies
  • Null-free

CSV specific

  • RFC 4180 compliant โ€“ including:
    • Newline and field separator characters in fields
    • Quote escaping
  • Configurable field separator
  • Support for line endings CRLF (Windows), CR (old macOS) and LF (Unix)
  • Unicode support

Reader specific

  • Support reading of some non-compliant (real world) data
  • Preserving line break character(s) within fields
  • Preserving the original line number (even with skipped and multi line records) โ€“ helpful for error messages
  • Auto-detection of line delimiters (can also be mixed)
  • Configurable data validation
  • Support for (optional) header lines (get field based on column name)
  • Support for skipping empty rows
  • Support for commented lines (skipping & reading) and configurable comment character
  • Support for random access file operations

Writer specific

  • Support for multiple quote strategies to differentiate between empty and null
  • Support for writing comments with proper quotation if needed

Requirements

  • Java 8

๐Ÿ’ก Android is not Java and is not officially supported. Although some basic checks are included in the continuous integration pipeline in order to verify that the library should work with Android 8.0 (API level 26).

CsvReader Examples

Iterative reading of some CSV data from a string

CsvReader.builder().build("foo1,bar1\r\nfoo2,bar2")
    .forEach(System.out::println);

Iterative reading of some CSV data with a header

NamedCsvReader.builder().build("header 1,header 2\nfield 1,field 2")
    .forEach(row -> row.getField("header 2"));

Iterative reading of a CSV file

try (CsvReader csv = CsvReader.builder().build(path)) {
    csv.forEach(System.out::println);
}

Custom settings

CsvReader.builder()
    .fieldSeparator(';')
    .quoteCharacter('"')
    .commentStrategy(CommentStrategy.SKIP)
    .commentCharacter('#')
    .skipEmptyRows(true)
    .errorOnDifferentFieldCount(false);

For more example see CsvReaderExample.java

CsvWriter Examples

Iterative writing of some data to a writer

CsvWriter.builder().build(new PrintWriter(System.out, true))
    .writeRow("header1", "header2")
    .writeRow("value1", "value2");

Iterative writing of a CSV file

try (CsvWriter csv = CsvWriter.builder().build(path)) {
    csv
        .writeRow("header1", "header2")
        .writeRow("value1", "value2");
}

Custom settings

CsvWriter.builder()
    .fieldSeparator(',')
    .quoteCharacter('"')
    .quoteStrategy(QuoteStrategy.REQUIRED)
    .lineDelimiter(LineDelimiter.LF);

For more example see CsvWriterExample.java

Upgrading from version 1.x

Please see UPGRADING.md for an overview of the main functionality of 1.x and how to upgrade them to version 2.


Sponsoring and partnerships

YourKit

YourKit was used to optimize the performance and footprint of FastCSV. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor.

fastcsv's People

Contributors

charphi avatar nathankleyn avatar osiegmar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.