|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object CSVFile
public abstract class CSVFile
CSVFile is a class used to handle Comma-Separated Values files.
It is abstract because it is the base class used for CSVFileReader
and CSVFileWriter
so you should use one of these (or both) according on what you need to do.
The simplest example for using the classes contained in this package is CSVFileExample
, that simply
converts one CSV file into another one that makes use of a different notation for field separator
and text qualifier.
The example just comprises the following lines:
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", ',', '\''); Vectorfields = in.readFields(); while(fields!=null) { out.writeFields(fields); fields = in.readFields(); } in.close(); out.close(); } }
Field Summary | |
---|---|
protected static char |
DEFAULT_FIELD_SEPARATOR
The default char used as field separator. |
protected static char |
DEFAULT_TEXT_QUALIFIER
The default char used as text qualifier |
protected char |
fieldSeparator
The current char used as field separator. |
protected char |
textQualifier
The current char used as text qualifier. |
Constructor Summary | |
---|---|
CSVFile()
CSVFile constructor with the default field separator and text qualifier. |
|
CSVFile(char sep)
CSVFile constructor with a given field separator and the default text qualifier. |
|
CSVFile(char sep,
char qual)
CSVFile constructor with given field separator and text qualifier. |
Method Summary | |
---|---|
char |
getFieldSeparator()
Get the current field separator. |
char |
getTextQualifier()
Get the current text qualifier. |
void |
setFieldSeparator(char sep)
Set the current field separator. |
void |
setTextQualifier(char qual)
Set the current text qualifier. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final char DEFAULT_FIELD_SEPARATOR
protected static final char DEFAULT_TEXT_QUALIFIER
protected char fieldSeparator
protected char textQualifier
Constructor Detail |
---|
public CSVFile()
public CSVFile(char sep)
sep
- The field separator to be used; overwrites the default onepublic CSVFile(char sep, char qual)
sep
- The field separator to be used; overwrites the default onequal
- The text qualifier to be used; overwrites the default oneMethod Detail |
---|
public void setFieldSeparator(char sep)
sep
- The new field separator to be used; overwrites the old onepublic void setTextQualifier(char qual)
qual
- The new text qualifier to be used; overwrites the old onepublic char getFieldSeparator()
public char getTextQualifier()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |