Top Description Fields Constructors Methods
org.hsqldb.util

pack-priv Class CSVWriter

extends Object
Class Inheritance
Imports
java.io.File, .FileOutputStream, .IOException, .OutputStreamWriter

helper class to write table data to a csv-file (comma separated values). the first line in file is a list of fieldnames, all following lines are data lines. a descptiontion of file format can be found on: http://www.wotsit.org/ usage: create a object using the constructor. call writeHeader for writing the filename header then add data with writeData. at the end close() closes the file.
Author
jeberle@users

Field Summary

Modifier and TypeField and Description
private int
private String
private OutputStreamWriter

Constructor Summary

AccessConstructor and Description
public
CSVWriter(File
the file to write data to
file
,
String
encoding to use or null (=defualt)
encoding
)

constructor.

Method Summary

Modifier and TypeMethod and Description
public void
close()

closes the csv file.

private void
doWriteData(String[] values)

private String
public void
writeData(String[]
data to write to csv-file
data
)

writes a data-record to the file.

public void
writeHeader(String[]
String[] with fieldnames
header
)

writes the csv header (fieldnames).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nbrRowsback to summary
private int nbrRows
newlineback to summary
private String newline
writerback to summary
private OutputStreamWriter writer

Constructor Detail

CSVWriterback to summary
public CSVWriter(File file, String encoding) throws IOException

constructor. creates a csv file for writing data to it

Parameters
file:File

the file to write data to

encoding:String

encoding to use or null (=defualt)

Method Detail

closeback to summary
public void close() throws IOException

closes the csv file.

doWriteDataback to summary
private void doWriteData(String[] values) throws IOException
toCsvValueback to summary
private String toCsvValue(String str)
writeDataback to summary
public void writeData(String[] data) throws IOException

writes a data-record to the file. note that data[] must have same number of elements as the header had.

Parameters
data:String[]

data to write to csv-file

writeHeaderback to summary
public void writeHeader(String[] header) throws IOException

writes the csv header (fieldnames). should be called after construction one time.

Parameters
header:String[]

String[] with fieldnames