Goto navigation

CSVReader

A small java class (5 kiB) with which you can parse CSV files. It knows different separator chars, multiline fields and separators inside field values.
Download CSVReader.jar and CSVReader.src.jar (2005-03-27).

Included is an JUnit test suite so that you can easily verify the correctness of the class.

Usage

import de.cweiske.tools.CSVReader;

class CSVReaderTest()
{
	public static void main(String[] args)
	{
		CSVReader cr = new CSVReader();
		String[][] arResult;
		
		//from http://www.ricebridge.com/products/csvman/why.htm
		cr.setData( "Name,Address,Born\r\n\"Smith, Adam\", \"Edinburgh\r\nScotland\", 1723\r\n\"Hobbes, Thomas\", \"Paris\", 1588");
		
		arResult = cr.parseData();
		
		//Smith, Adam
		System.out.println(arResult[1][0]);
	}
}

javadoc

Have a look at the javadoc.

License

This class may be used under the terms of the GPL as long the project is non-commerical. For commercial projects, please contact me.
Navigation
File: misc_classes.htm | last update: 2023-04-06 23:45:02 Valid XHTML Valid CSS