com.mindprod.csv
Class LinesToCSV
java.lang.Object
com.mindprod.csv.LinesToCSV
public final class LinesToCSV
- extends java.lang.Object
Converts text file of one field per line to a comma-separated CSV file.
Use: java.exe com.mindprod.LinesToCSV somefile.txt 3
How many lines should be grouped together on one line of the CSV file.
Output is somefile.csv. somefile.txt is left unchanged.
- Since:
- 2010-12-14
- Version:
- 1.1 2011-01-25 allow you to specify encoding
- Author:
- Roedy Green, Canadian Mind Products
Constructor Summary |
LinesToCSV(java.io.File file,
int grouping,
char separatorChar,
char quoteChar,
char commentChar,
java.lang.String encoding)
convert a txt file to CSV, constructor. |
Method Summary |
static void |
main(java.lang.String[] args)
Simple command line interface to LinesToCSV. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LinesToCSV
public LinesToCSV(java.io.File file,
int grouping,
char separatorChar,
char quoteChar,
char commentChar,
java.lang.String encoding)
throws java.io.IOException
- convert a txt file to CSV, constructor. Just create. There are no methods to call.
- Parameters:
file
- CSV file to be packed to remove excess space and quotes.grouping
- how many lines to collect together as one csv line, one field per line.separatorChar
- field separator character, usually ',' in North America, ';' in Europe and sometimes '\t' for
tab for the output file. It is tab for the input file.
Note this is a 'char' not a "string".quoteChar
- character used to quote fields containing awkward chars.commentChar
- char to use to introduce comments. Use (char) 0 if none. Only one character allowed.
Note this is a 'char' not a "string". For output file. No comment presumed in input file.encoding
- encoding of input and output file.
- Throws:
java.io.IOException
- if problems reading/writing file
main
public static void main(java.lang.String[] args)
- Simple command line interface to LinesToCSV. Converts text file of one field per line to a comma-separated CSV file.
java.exe com.mindprod.LinesToCSV somefile.txt 3
How many lines should be grouped together on one line of the CSV file.
Output is somefile.csv. somefile.txt is left unchanged.
You can use LinesToCSV constructor in your own programs.
- Parameters:
args
- name of csv file to remove excess quotes and space