Convert a flat file to Java objects

Does anyone know of any good libraries for converting a flat file to Java objects? I found flatworm , but I'm looking for alternatives.

+7
java flat-file
source share
6 answers

FFP - Flat File Parsing Library
http://jffp.sourceforge.net/

+4
source share

Quick update: flatworm has been inactive for a while, there is a fork named BeanIO: http://www.beanio.org/

+9
source share

I have not used this JFlat , but it looks like this Framework provides conversion from a flat file to a Java object.

Similarly, BeanIO and Jsefa also provide a simple and flexible API.

You can try with FlatPack - but it's OLD and the docs aren't as good as JFlat or BeanIO

Apache Camel has a Flatpack component, and since 2.10 - a BeanIO component

+2
source share

Another alternative that I wrote that using Java Annotations is JFileHelpers - http://jfilehelpers.com

An example of an annotated bean:

@FixedLengthRecord() public class Customer { @FieldFixedLength(4) public Integer custId; @FieldAlign(alignMode=AlignMode.Right) @FieldFixedLength(20) public String name; @FieldFixedLength(3) public Integer rating; @FieldTrim(trimMode=TrimMode.Right) @FieldFixedLength(10) @FieldConverter(converter = ConverterKind.Date, format = "dd-MM-yyyy") public Date addedDate; @FieldFixedLength(3) @FieldOptional public String stockSymbol; } 

Then you just need to:

  FileHelperEngine<Customer> engine = new FileHelperEngine<Customer>(Customer.class); List<Customer> customers = new ArrayList<Customer>(); customers = engine.readResource( "/samples/customers-fixed.txt"); 
+2
source share

You can also try Fixedformat4j . I like the annotation approach, and it’s very simple to define the format of an arbitrary field.

+1
source share

Would you like to consider JRecordBind (I am its author)

Unlike others, it can both analyze and create flat files, and uses a simple XML scheme (so you don’t need to learn another configuration syntax). Some users recycle the same XSD to create both webservice and flat files.

ps: I recently translated the code on github

+1
source share

All Articles