读取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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值