Skip to content

Repository files navigation

中文版

easy-txt: Delimited Text File Reader/Writer for Java

Read & write delimited text files like EasyExcel. Annotation-based Bean mapping, 2G+ large file support, batch processing.

Maven Central Java CI Java License GitHub release GitHub Stars Blog

// Read: 3 lines
EasyTxt.read(file, UserBean.class, ",", new BeanReadListener()).doRead();

// Write: 3 lines
EasyTxt.write(file, UserBean.class, ",", pageNo, pageSize, this::queryPage).doWrite();

Features

  • Annotation-based Bean mapping@TxtFiled, @DateFormatFiled, @NumberFormatFiled
  • Two index modes — Fixed-index & auto-ascending index
  • Batch read/write — Paginated callbacks for large datasets
  • 2G+ large file support — 111s write / 105s read for 2.52GB (see benchmark below)
  • Rich type conversion — String, int, long, BigDecimal, Date, LocalDate, LocalDateTime, and more
  • Custom separator — CSV, pipe (|), tab, or any delimiter
  • Zero heavy framework — No Spring, pure Java + Hutool + Commons IO

Comparison

Feature easy-txt OpenCSV Apache Commons CSV
Annotation Bean mapping ❌ (via MappingStrategy)
Batch page callback
2G+ large file
Custom separator
Type converters built-in ✅ (15+ types) ⚠️ (basic)
Date/Number format annotations

Installation

Maven

<dependency>
    <groupId>com.small</groupId>
    <artifactId>easy-txt-core</artifactId>
    <version>1.1.0</version>
</dependency>

Gradle

implementation 'com.small:easy-txt-core:1.1.0'

Build from Source

git clone https://github.com/sm-rose/easy-txt.git
cd easy-txt
mvn clean package

The JAR will be generated at easy-txt-core/target/easy-txt-core-1.1.0.jar.


Quick Start

1. Define Bean

@Data
public class UserBean {
    @TxtFiled(index = 0)
    private String name;

    @TxtFiled(index = 1)
    private int age;

    @TxtFiled(index = 2)
    private BigDecimal salary;

    @TxtFiled(index = 3)
    @DateFormatFiled("yyyy-MM-dd")
    private Date birth;
}

2. Read File

// Line-by-line via listener
EasyTxt.read(file, UserBean.class, ",", new BeanReadListener()).doRead();

// Batch via consumer
EasyTxt.read(file, BeanTestVO.class, "\\|", pageSize, pageList -> {
    pageList.forEach(System.out::println);
}).doRead();

3. Write File

EasyTxt.write(file, BeanTest.class, ",", pageNo, pageSize, (pNum, pSize) -> {
    return queryPageData(pNum, pSize);
}).doWrite();

Full examples in the easy-txt-test module.


Large File Performance

Environment: Windows 10, 16GB RAM, mechanical HDD (4 years old).

Simple types (30 columns per row)

Operation Rows Size Time
Write 2,000,000 2.52 GB 111s
Read 2,000,000 2.52 GB 105s

Mixed types (22 columns with conversion)

Operation Rows Size Time
Write 8,000,000 2.21 GB 186s
Read 8,000,000 2.52 GB 223s

See BigFileDemoTest and BigFileTypeDemoTest.


Change Log

  • v1.1.0 — Type converters, date/number format annotations, Java 8 time support
  • v1.0.0 — Initial release: batch read/write, bean mapping

About

Easy-txt: Read & write delimited text files like EasyExcel. Annotation-based Bean mapping, 2G+ large file support, batch processing. Java library for CSV/TSV/pipe-delimited files

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages