DataFile

Java Data File Read/Write Utility

datafile.jar is a Java data file read/write utility that provides a convenient set of interfaces for reading and writing data to and from files in widely accepted format such as comma separated values (CSV), fixed width, tab separated, as well as others.

SAMPLE USAGE:

/*
   Creating a reader for CSV file using
   ISO-8859-1
*/

DataFile read =
  DataFile.createReader("8859_1");

read.setDataFormat(new CSVFormat());
// first line is column header
read.containsHeader(true);

try {

  read.open(new File("/data/test.csv"));

  for (DataRow row = read.next();
       row != null;
       row = read.next()) {

    String text = row.getString(0);
    // retrieval using column header
    int number1 = row.getInt("FIRST_NUMBER", 0);
    double number2 = row.getDouble(2);

    // use the retrieved data ...

  }
}

finally {
  read.close();
}

/*
   Creating a writer for data file with
   European encoding ISO-8859-2 (European)
   using tab separated format.
   (rewrite existing file)
*/

DataFile write =
  DataFile.createWriter("8859_2", false);

write.setDataFormat(new TabFormat());

try {

  write.open(new File("/data/test.txt"));

  for (DataRow row = write.next();
       row != null;
       row = write.next()) {

    row.add("some German text");
    row.add(123);
    row.add(13323.23d);

  }
}

finally {
  write.close();
}

Release Notes

2004.04.24 SATURDAY
+ Released source code via SourceForge
  under GNU Library or Lesser General Public License (LGPL).
+ Added unit test for CSV, tab delimited, and fixed width
  data formats.

2004.01.30 FRIDAY
+ Added few more retrieval interfaces for DataRow.
+ Added "getHeaderNames()" to DataFile.

2003.09.08 MONDAY
+ Bug Fix: CSV encoding omitted starting quote
  (Thanks to Phil Duhs for reporting this problem)
+ removed debugging code from DataFile

2003.07.23 WEDNESDAY
+ Bug Fix: DataRow no longer throws IndexOutofBoundsException
  when accessing trailing empty items.
  (Thanks, Dennis Buijs, for reporting the bug)

2003.04.29 TUESDAY
+ Bug Fix: CSV Format now handles new line character within
  the CSV encoded data cell.
+ Added header support (first row of the data file is header)
+ Added data retrieval using column name

SourceForge.net Logo

Copyright © 2004 Infomata.