1 package net.sf.pzfilereader.examples.fixedlengthdynamiccolumns;
2
3
4
5
6
7
8 import java.io.File;
9
10 import net.sf.pzfilereader.DataSet;
11 import net.sf.pzfilereader.DefaultPZParserFactory;
12 import net.sf.pzfilereader.DataSet;
13 import net.sf.pzfilereader.PZParser;
14
15 /**
16 * @author zepernick
17 *
18 * TODO To change the template for this generated type comment go to Window -
19 * Preferences - Java - Code Style - Code Templates
20 */
21 public class FixedLengthWithPZMap {
22 public static void main(final String[] args) throws Exception {
23 String mapping = getDefaultMapping();
24 String data = getDefaultDataFile();
25 call(mapping, data);
26
27 }
28
29 public static String getDefaultDataFile() {
30 return "PEOPLE-FixedLength.txt";
31 }
32
33 public static String getDefaultMapping() {
34 return "PEOPLE-FixedLength.pzmap.xml";
35 }
36
37 public static void call(String mapping, String data) throws Exception {
38 final PZParser pzparser = DefaultPZParserFactory.getInstance().newFixedLengthParser(
39 new File(mapping), new File(data));
40 final DataSet ds = pzparser.parse();
41
42 final String[] colNames = ds.getColumns();
43
44 while (ds.next()) {
45 for (int i = 0; i < colNames.length; i++) {
46 System.out.println("COLUMN NAME: " + colNames[i] + " VALUE: " + ds.getString(colNames[i]));
47 }
48
49 System.out.println("===========================================================================");
50 }
51
52 }
53 }