To read DBF files in FoxPro format

Source: Internet
Author: User
Tags format end

Original source

Finally finish the DBF file read and write Java source code, welcome to use



Modify the following code



    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);            }&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSp;     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 file Definition Format: http://www.clicketyclick.dk/databases/xbase/format/dbf.html








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.