原文出处
终于整理完dbf文件读写的java源码,欢迎使用
修改以下代码
private void init(inputstream inputstream) throws jdbfexception { try { stream = new datainputstream(inputstream); int i = readheader(); fields = new jdbfield[i]; int j = 1; for(int k = 0; k < i; k++) { fields[k] = readfieldheader(); j += fields[k].getlength(); }
if(stream.read() < 1) throw new jdbfexception("unexpected end of file reached."); nextrecord = new byte[j]; try { //stream.readfully(nextrecord); stream.read(new byte[263]); stream.readfully(nextrecord); } catch(eofexception eofexception) { nextrecord = null; stream.close(); } } catch(ioexception ioexception) { throw new jdbfexception(ioexception); } }
private int readheader() throws ioexception, jdbfexception { byte abyte0[] = new byte[16]; try { stream.readfully(abyte0); } catch(eofexception eofexception) { throw new jdbfexception("unexpected end of file reached."); } int i = abyte0[8]; if(i < 0) i += 256; i += 256 * abyte0[9]; i -= 264; i = –i / 32; //i = –i / 32; //i–; try { stream.readfully(abyte0); } catch(eofexception eofexception1) { throw new jdbfexception("unexpected end of file reached."); } return i; }
dbf文件定义格式:http://www.clicketyclick.dk/databases/xbase/format/dbf.html
