public abstract class CSVFile
extends java.lang.Object
This is the abstract base clase used by CSVFileReader
and
CSVFileWriter
.
The following simple example converts one CSV file into another that uses a different notation for field separator and text qualifier.
import java.util.*; import java.io.*; public class CSVFileExample { public static void main( String[] args ) throws FileNotFoundException,IOException { CSVFileReader in = new CSVFileReader("csv_in.txt", ';', '"'); CSVFileWriter out = new CSVFileWriter("csv_out.txt", ',', '\''); List fields = in.readFields(); while( fields != null ) { out.writeFields( fields ); fields = in.readFields(); } in.close(); out.close(); } }
Modified by Philip R. Burns at Northwestern University.
Modifier and Type | Field and Description |
---|---|
protected static char |
DEFAULT_QUALIFIER
The default char used as text qualifier
|
protected static char |
DEFAULT_SEPARATOR
The default char used as field separator.
|
protected char |
qualifier
The current char used as text qualifier.
|
protected char |
separator
The current char used as field separator.
|
Constructor and Description |
---|
CSVFile()
CSVFile constructor with the default field separator and text qualifier.
|
CSVFile(char separator)
CSVFile constructor with given field separator.
|
CSVFile(char separator,
char qualifier)
CSVFile constructor with given field separator and text qualifier.
|
Modifier and Type | Method and Description |
---|---|
char |
getQualifier()
Get the current text qualifier.
|
char |
getSeparator()
Get the current field separator.
|
void |
setQualifier(char qualifier)
Set the text qualifier.
|
void |
setSeparator(char separator)
Set the field separator.
|
protected static final char DEFAULT_SEPARATOR
protected static final char DEFAULT_QUALIFIER
protected char separator
protected char qualifier
public CSVFile()
public CSVFile(char separator)
separator
- The field separator.public CSVFile(char separator, char qualifier)
separator
- The field separator to used.qualifier
- The text qualifier to be use.public void setSeparator(char separator)
separator
- The field separator to use.public void setQualifier(char qualifier)
qualifier
- The new text qualifier to use.public char getSeparator()
public char getQualifier()