DBF数据库文件Java读写类库: jdbf

jopen 12年前

使用java实现的dbf文件读写库,非常方便。

示例生成一个DBF文件:

public static void main(String args[])          throws Exception      {          JDBField[] fields = {              new JDBField("ID", 'C', 8, 0),              new JDBField("Name", 'C', 32, 0),              new JDBField("TestN", 'N', 20, 0), //第三个参数值一定不大于20              new JDBField("TestF", 'F', 20, 6), //F类型与N类型同,且第四个参数值有小数位数,否则会截短              new JDBField("TestD", 'D', 8, 0)          };          //DBFReader dbfreader = new DBFReader("E:\\hexiong\\work\\project\\book2.dbf");          DBFWriter dbfwriter = new DBFWriter("./testwrite.dbf", fields);            Object[][] records = {              {"1", "hexiong", new Integer(500), new Double(500.123), new Date() },              {"2", "hefang", new Integer(600), new Double(600.234), new Date() },              {"3", "heqiang", new Integer(700), new Double(700.456), new Date() }          };            for (int i=0; i<records.length; i++){            dbfwriter.addRecord(records[i]);          }          dbfwriter.close();          System.out.println("testwrite.dbf write finished.......");      }
读一个DBF文件:
public static void main(String args[])          throws Exception      {          //DBFReader dbfreader = new DBFReader((new URL("http://www.svcon.com/us48st.dbf")).openStream());          //DBFReader dbfreader = new DBFReader("F:\\work\\book2.dbf");          DBFReader dbfreader = new DBFReader("./book2.dbf");          //DBFReader dbfreader = new DBFReader("E:\\hexiongshare\\test.dbf");          int i;          for (i=0; i<dbfreader.getFieldCount(); i++) {            System.out.print(dbfreader.getField(i).getName()+"  ");          }          System.out.print("\n");          for(i = 0; dbfreader.hasNextRecord(); i++)          {              Object aobj[] = dbfreader.nextRecord(Charset.forName("GBK"));              for (int j=0; j<aobj.length; j++)                System.out.print(aobj[j]+"  |  ");              System.out.print("\n");          }            System.out.println("Total Count: " + i);      }

项目主页:http://www.open-open.com/lib/view/home/1340678527780