DBF文件的读取方法:
public List<Dbf> readerDbf(String path){
List<Dbf> dbfs = new ArrayList<Dbf>();
File file = new File(path);
Dbf dbf;
DBFReader reader;
JDBField field;
String field0;
String field1;
try {
in = new FileInputStream(file);
reader = new DBFReader(in);
for(int i = 0; i < reader.getFieldCount(); i ++){
field = reader.getField(i);
if(i % 2 == 0) field0 = field.getName();
if(i % 2 != 0) field1 = field.getName();
}
for(int i = 0; reader.hasNextRecord(); i ++){
Object[] obj = reader.nextRecord();
dbf = new Dbf();
for(int j = 0; j < obj.length; j ++){
System.out.println(obj[j]);
if(j % 2 == 0) dbf.setProperty(Integer.parseInt(String.valueOf(obj[j]) ));
if(j % 2 == 1) dbf.setValue(String.valueOf(obj[j]));
}
dbfs.add(dbf);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JDBFException e) {
e.printStackTrace();
}
return dbfs;
}
注:对2求余,是因为当前DBF文件中只有两个字段,所以才对2求余进行不同类型的数据封装。