急!请问如何用JAVA直接读取DBF文件的内容而不用建立ODBC

ebrmp 2002-03-27 09:25:47
急!请问如何用JAVA直接读取DBF文件的内容而不用建立ODBC
最好给个例子
...全文
279 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
LeeJah163 2010-06-18
  • 打赏
  • 举报
回复
public class TestReadDBF {

private static void readDBF(String fileName) {
try {
InputStream in = new FileInputStream(fileName);
DBFReader dbfreader = new DBFReader(in);
// dbfreader.setCharactersetName("GB2312");
// for (int b = 0; b < dbfreader.getFieldCount(); b++) {
// if (b > 0)
// System.out.print(dbfreader.getField(b).getName().trim().toUpperCase()+",");
// if (b == (dbfreader.getFieldCount() - 1))
// System.out.print("\n");
// }
Object[] rowObj;
while ((rowObj = dbfreader.nextRecord()) != null) {
for (int i = 0; i < rowObj.length; i++) {
System.out.print(PageEncoding.encode(rowObj[i].toString()) + " ");
}
System.out.print("\n");
}
} catch (Exception e) {
}
}

public static void main(String[] args) {
// String encoding = System.getProperty("file.encoding");
// System.out.println(encoding);
TestReadDBF.readDBF("e:/a0200.dbf");
}
}
家有笨狗 2002-03-27
  • 打赏
  • 举报
回复
2a. field descriptor array in dbf header (fix 32 bytes for each field)
========================================

byte size contents description applies for (supported by)
----+----+--------+----------------------------+-----------------------------
0 11 asci field name, 0x00 termin. all
11 1 asci field type (see 2b) all
12 4 n,n,n,n fld address in memory d3
n,n,0,0 offset from record begin fp
0,0,0,0 ignored fs, d4, d5, fb, cl
16 1 byte field length, bin (see 2b) all \ fs,cl: for c field type,
17 1 byte decimal count, bin all / both used for fld lng
18 2 0,0 reserved all
20 1 byte work area id d4, d5
0x00 unused fs, d3, fb, fp, cl
21 2 n,n multi-user dbase d3, d4, d5
0,0 ignored fs, fb, fp, cl
23 1 0x01 set fields d3, d4, d5
0x00 ignored fs, fb, fp, cl
24 7 0..0 reserved all
31 1 0x01 field is in .mdx index d4, d5
0x00 ignored fs, d3, fb, fp, cl

padding...
家有笨狗 2002-03-27
  • 打赏
  • 举报
回复
2a. field descriptor array in dbf header (fix 32 bytes for each field)
========================================

byte size contents description applies for (supported by)
----+----+--------+----------------------------+-----------------------------
0 11 asci field name, 0x00 termin. all
11 1 asci field type (see 2b) all
12 4 n,n,n,n fld address in memory d3
n,n,0,0 offset from record begin fp
0,0,0,0 ignored fs, d4, d5, fb, cl
16 1 byte field length, bin (see 2b) all \ fs,cl: for c field type,
17 1 byte decimal count, bin all / both used for fld lng
18 2 0,0 reserved all
20 1 byte work area id d4, d5
0x00 unused fs, d3, fb, fp, cl
21 2 n,n multi-user dbase d3, d4, d5
0,0 ignored fs, fb, fp, cl
23 1 0x01 set fields d3, d4, d5
0x00 ignored fs, fb, fp, cl
24 7 0..0 reserved all
31 1 0x01 field is in .mdx index d4, d5
0x00 ignored fs, d3, fb, fp, cl

padding...
家有笨狗 2002-03-27
  • 打赏
  • 举报
回复
01 3 yymmdd last update digits all
04 4 ulong number of records in file all
08 2 ushort header size in bytes all
10 2 ushort record size in bytes all
12 2 0,0 reserved all
14 1 0x01 begin transaction d4, d5
0x00 end transaction d4, d5
0x00 ignored fs, d3, fb, fp, cl
15 1 0x01 encryptpted d4, d5
0x00 normal visible all
16 12 0 (1) multi-user environment use d4,d5
28 1 0x01 production index exists fp, d4, d5
0x00 index upon demand all
29 1 n language driver id d4, d5
0x01 codepage 437 dos usa fp
0x02 codepage 850 dos multi ling fp
0x03 codepage 1251 windows ansi fp
0xc8 codepage 1250 windows ee fp
0x00 ignored fs, d3, fb, fp, cl
30 2 0,0 reserved all
32 n*32 field descriptor, see (2a) all
+1 1 0x0d header record terminator all

padding...
muqiao 2002-03-27
  • 打赏
  • 举报
回复
何不使用mysql
家有笨狗 2002-03-27
  • 打赏
  • 举报
回复
2. dbf header (variable size, depending on field count)
=======================================================

byte size contents description applies for (supported by)
----+----+--------+----------------------------+-----------------------------
00 1 0x03 plain .dbf fs, d3, d4, d5, fb, fp, cl
0x04 plain .dbf d4, d5 (fs)
0x05 plain .dbf d5, fp (fs)
0x43 with .dbv memo var size fs
0xb3 with .dbv and .dbt memo fs
0x83 with .dbt memo fs, d3, d4, d5, fb, fp, cl
0x8b with .dbt memo in d4 format d4, d5
0x8e with sql table d4, d5
0xf5 with .fmp memo fp

padding...
家有笨狗 2002-03-27
  • 打赏
  • 举报
回复
这里是dbf文件的格式,如果你有耐心的话可以试一试。
dbase flie format
----------------------------------------------------------------------------
genaral format of .dbf files in xbase languages 18-nov-96
----------------------------------------------------------------------------
applies for / supported by:

fs = flagship d3 = dbaseiii+
fb = foxbase d4 = dbaseiv
fp = foxpro d5 = dbasev
cl = clipper


1. dbf structure
================

byte description
------+--------------------------------------
0..n .dbf header (see 2 for size, byte 8)
n+1 1st record of fixed length (see 2&3) \
2nd record (see 2 for size, byte 10) \ if dbf is
... / not empty
last record /
last optional: 0x1a (eof byte)


padding...
家有笨狗 2002-03-27
  • 打赏
  • 举报
回复
你可以直接打开dbf文件,再按照dbf文件规范自己分析。
下面是dbf文件的格式,如果你有耐心的话可以试一试。
dbase flie format
----------------------------------------------------------------------------
genaral format of .dbf files in xbase languages 18-nov-96
----------------------------------------------------------------------------
applies for / supported by:

fs = flagship d3 = dbaseiii+
fb = foxbase d4 = dbaseiv
fp = foxpro d5 = dbasev
cl = clipper


1. dbf structure
================

byte description
------+--------------------------------------
0..n .dbf header (see 2 for size, byte 8)
n+1 1st record of fixed length (see 2&3) \
2nd record (see 2 for size, byte 10) \ if dbf is
... / not empty
last record /
last optional: 0x1a (eof byte)


padding...
ebrmp 2002-03-27
  • 打赏
  • 举报
回复
说具体点好吗?
jimw 2002-03-27
  • 打赏
  • 举报
回复
了解dbf文件的格式后,就很容易解决了。

ebrmp 2002-03-27
  • 打赏
  • 举报
回复
你说的那个还是要借助于ODBC的阿
有不用ODBC的吗
zjp009 2002-03-27
  • 打赏
  • 举报
回复
对,直接用JDBC DRIVER。
Hawk123 2002-03-27
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/600/600934.xml?temp=.891781

Use jdbc driver

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧