/
JavaDBFReaderWithFieldNamesTest.java
56 lines (37 loc) · 1.42 KB
/
JavaDBFReaderWithFieldNamesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package deringo.dbfsample.javadbf;
import java.io.*;
import com.linuxense.javadbf.*;
public class JavaDBFReaderWithFieldNamesTest {
public static void main(String args[]) throws IOException {
read(new FileInputStream(args[0]));
}
public static void read(InputStream in) {
DBFReader reader = null;
try {
// create a DBFReader object
reader = new DBFReader( in );
// get the field count if you want for some reasons like the following
int numberOfFields = reader.getFieldCount();
// use this count to fetch all field information
// if required
for (int i = 0; i < numberOfFields; i++) {
DBFField field = reader.getField(i);
// do something with it if you want
// refer the JavaDoc API reference for more details
//
System.out.println(field.getName());
}
// Now, lets us start reading the rows
DBFRow row;
while ((row = reader.nextRow()) != null) {
System.out.println(row.getString("PHONE"));
}
// By now, we have iterated through all of the rows
} catch (DBFException e) {
e.printStackTrace();
}
finally {
DBFUtils.close(reader);
}
}
}