iryndin / jdbf

Java utility to read/write DBF files
108 stars 77 forks source link

Error creating dbf when Integer fields are defined. #53

Open JosepMariaGomez opened 2 years ago

JosepMariaGomez commented 2 years ago

Error on read dbf files created with jdbf if there is one (or more) field of Integer type.

            String fieldsInfo = "CODE,C,12,0|TITLE,C,40,0|CATEGORY,I,5,0";
            DbfMetadata meta1 = DbfMetadataUtils.fromFieldsString(fieldsInfo);
            meta1.setType(DbfFileTypeEnum.FoxBASEPlus1);
            DbfWriter writer = new DbfWriter(meta1, out);  // out is a OutputStream to send the file to the client side.
            writer.setStringCharset(Charset.forName("ISO-8859-1")); // ISO-LATIN-1
            Map<String, Object> map = new HashMap<>();
            map.put("CODE", "1");
            map.put("TITLE", "FIRST");
            map.put("CATEGORY", 1);
            writer.write(map);
            writer.close();

No error is raised during creation process.

           String fieldsInfo = "CODE,C,12,0|TITLE,C,40,0|CATEGORY,N,5,0";

Changing the definition to N, converts the field to Float, and dbf file can be readed (with an external dbf browser).

Many thanks.