Overview

This library is useful for processing csv files. Csv I/O supports read/write csv file.

Sample programs

Read csv file

import java.io.BufferedReader;
import java.io.FleReader;
import java.io.IOException;

import jp.sourceforge.talisman.csvio.CsvLine;
import jp.sourceforge.talisman.csvio.CsvParser;

/**
 * Sample program for reading CSV file by Csv I/O library.
 *
 * @author Haruaki Tamada
 * @version 1.0 2008-07-08
 */
public class CsvReadingSample{
    /**
     * We can get all of lines by getAllLines method in CsvParser class.
     */
    public CsvLine[] parse(String file) throws IOException{
        BufferedReader in = new BufferedReader(new FileReader(file));
        CsvParser parser = new CsvParser(in);

        return parser.getAllLines();
    }

    /**
     * CsvParser supports Iterator for traversing all of lines.
     */
    public CsvLine[] parse2(String file) throws IOException{
        BufferedReader in = new BufferedReader(new FileReader(file));
        CsvParser parser = new CsvParser(in);
        List<CsvLine> list = new ArrayList<CsvLine>();

        for(CsvLine line: parser){
            list.add(line);
        }
        return list.toArray(new CsvLine[list.size()]);
    }

    public static void main(String[] args) throws Exception{
        CsvReadingSample sample = new CsvReadingSample();
        for(String arg: args){
            sample.parse(arg);
        }
    }
}

Write csv file

import java.io.Writer;
import java.io.IOException;

import jp.sourceforge.talisman.csvio.CsvLine;
import jp.sourceforge.talisman.csvio.CsvLineWriter;

/**
 * Sample program for writing CSV file by Csv I/O library.
 *
 * @author Haruaki Tamada
 * @version 1.0 2008-07-08
 */
public class CsvWritingSample{
    /**
     * We can write CsvLine object by CsvLineWriter object.
     */
    public void write(Writer writer, CsvLine[] lines) throws IOException{
        CsvLineWriter out = new CsvLineWriter(writer);
        for(CsvLine line: lines){
            out.write(line);
        }
    }
}