1 package net.sf.pzfilereader.examples.delimitedcolumnnamesinfile;
2
3
4
5
6
7
8 import java.io.File;
9
10 import net.sf.pzfilereader.DataError;
11 import net.sf.pzfilereader.DataSet;
12 import net.sf.pzfilereader.DefaultPZParserFactory;
13 import net.sf.pzfilereader.PZParser;
14 import net.sf.pzfilereader.ordering.OrderBy;
15 import net.sf.pzfilereader.ordering.OrderColumn;
16
17 /**
18 * @author zepernick
19 *
20 * TODO To change the template for this generated type comment go to Window -
21 * Preferences - Java - Code Style - Code Templates
22 */
23 public class DelimitedColumnNamesInFile {
24 public static void main(final String[] args) throws Exception {
25 String[] colNames = null;
26 OrderBy orderby = null;
27
28
29
30
31 final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(
32 new File("PEOPLE-CommaDelimitedWithQualifier.txt"), ',', '"');
33 final DataSet ds = pzparser.parse();
34
35
36 orderby = new OrderBy();
37 orderby.addOrderColumn(new OrderColumn("CITY", false));
38 orderby.addOrderColumn(new OrderColumn("LASTNAME", true));
39 ds.orderRows(orderby);
40
41 colNames = ds.getColumns();
42
43 while (ds.next()) {
44 for (int i = 0; i < colNames.length; i++) {
45 System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i]));
46 }
47
48 System.out.println("===========================================================================");
49 }
50
51 if (ds.getErrors() != null && ds.getErrors().size() > 0) {
52 System.out.println("FOUND ERRORS IN FILE....");
53 for (int i = 0; i < ds.getErrors().size(); i++) {
54 final DataError de = (DataError) ds.getErrors().get(i);
55 System.out.println("Error: " + de.getErrorDesc() + " Line: " + de.getLineNo());
56 }
57 }
58
59 }
60 }