2.
import com.linuxense.javadbf.DBFField
import com.linuxense.javadbf.DBFReader
3.实例
package com.realhope.jdbf
import java.io.FileInputStream
import java.io.InputStream
import com.linuxense.javadbf.DBFField
import com.linuxense.javadbf.DBFReader
public class readDBF {
public static void readDBF(String path) {
InputStream fis = null
try {
fis = new FileInputStream(path)
// 根据输入流初始化一个DBFReader实例,用来读取DBF文件信息
DBFReader reader = new DBFReader(fis)
// 调用DBFReader对实例方法得到path文件中字段的个数
int fieldsCount = reader.getFieldCount()
// 取出字段信息
for (int i = 0i <fieldsCounti++) {
DBFField field = reader.getField(i)
System.out.print(field.getName())
}
Object[] rowValues
// 一条条取出path文件中记录rowValues.length
while ((rowValues = reader.nextRecord()) != null) {
for (int i = 0i <rowValues.lengthi++) {
System.out.println(rowValues[i])
}
}
} catch (Exception e) {
e.printStackTrace()
} finally {
try {
fis.close()
} catch (Exception e) {
}
}
}
public static void main(String[] args) {
readDBF.readDBF("Y:/dbf/01-04-2013/sjshq.DBF")
}
}
Java读取DBF文件,需要加载开源jar包JavaDBF.jar,然后使用里面的方法进行读写,示例如下:
package searchpublic class ReadDBF {
public static void main(String args[])
{
readDBF()
}
private static void readDBF()
{
try
{
System.out.println("正在读取文件!")
DBFReader dbfreader = new DBFReader("D:\\ZG2011格式.dbf")
for(int b = 0b<dbfreader.getFieldCount()b++)
{
if(b>0)
{ System.out.print(",")}
System.out.print(dbfreader.getField(b).getName().trim().toUpperCase())
if(b == (dbfreader.getFieldCount()-1))
System.out.print("\n")
}
for(int i = 0dbfreader.hasNextRecord()i++)
{
String[] aobj = dbfreader.nextRecordString()
for(int b = 0b<dbfreader.getFieldCount()b++)
{
if(b>0)
System.out.print(",")
System.out.print(aobj[b].trim())
if(b == (dbfreader.getFieldCount()-1))
System.out.print("\n")
}
}
System.out.println("读取文件成功!")
}
catch(Exception e)
{
System.out.print(e.getMessage())
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)