Package org.evolvis.tartools.csvfile
Class CSVFile
- java.lang.Object
-
- org.evolvis.tartools.csvfile.CSVFile
-
- Direct Known Subclasses:
CSVFileReader,CSVFileWriter
public abstract class CSVFile extends Object
CSVFile is a Java™ class used to handle comma-separated value files. It is an abstract base class forCSVFileReaderandCSVFileWriter, 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 the following example that simply converts one CSV file into another one that makes use of a different notation for field separator and text qualifier (quote character). It just comprises the following lines:package org.evolvis.tartools.csvfile; import java.io.IOException; import java.util.List; public class CSVFileExample { public static void main(String[] args) throws 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(); } }- Author:
- Fabrizio Fazzino
-
-
Field Summary
Fields Modifier and Type Field Description static StringCRstatic StringCRLFprotected static charDEFAULT_FIELD_SEPARATORThe default char used as field separator.protected static charDEFAULT_TEXT_QUALIFIERThe default char used as text qualifier.protected charfieldSeparatorThe current char used as field separator.static StringLFprotected chartextQualifierThe current char used as text qualifier.
-
Constructor Summary
Constructors Constructor Description CSVFile(char sep, char qual)CSVFile constructor with given field separator and text qualifier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description chargetFieldSeparator()Gets the current field separator.chargetTextQualifier()Gets the current text qualifier.voidsetFieldSeparator(char sep)Sets the current field separator.voidsetTextQualifier(char qual)Sets the current text qualifier.
-
-
-
Field Detail
-
CR
public static final String CR
- See Also:
- Constant Field Values
-
LF
public static final String LF
- See Also:
- Constant Field Values
-
CRLF
public static final String CRLF
- See Also:
- Constant Field Values
-
DEFAULT_FIELD_SEPARATOR
protected static final char DEFAULT_FIELD_SEPARATOR
The default char used as field separator.- See Also:
- Constant Field Values
-
DEFAULT_TEXT_QUALIFIER
protected static final char DEFAULT_TEXT_QUALIFIER
The default char used as text qualifier.- See Also:
- Constant Field Values
-
fieldSeparator
protected char fieldSeparator
The current char used as field separator.
-
textQualifier
protected char textQualifier
The current char used as text qualifier.
-
-
Method Detail
-
setFieldSeparator
public void setFieldSeparator(char sep)
Sets the current field separator.- Parameters:
sep- The new field separator to be used; overwrites the old one
-
setTextQualifier
public void setTextQualifier(char qual)
Sets the current text qualifier.- Parameters:
qual- The new text qualifier to be used; overwrites the old one
-
getFieldSeparator
public char getFieldSeparator()
Gets the current field separator.- Returns:
- The char containing the current field separator
-
getTextQualifier
public char getTextQualifier()
Gets the current text qualifier.- Returns:
- The char containing the current text qualifier
-
-