当前位置导航:炫浪网>>网络学院>>网页制作>>JSP教程

读取foxpro格式的dbf文件


原文出处

终于整理完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






相关内容
赞助商链接