iryndin / jdbf

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

Writes are not working #16

Open cooldemo opened 9 years ago

cooldemo commented 9 years ago

The writes to a dbf file are broken - header is not written properly.

laptio commented 8 years ago

I think, I have the same problem. When I'm trying to open file, I have "Table 'xx.dbf' has become corrupted. Table will need to be repaired before using again"

laptio commented 8 years ago

I think smth wrong with this:

private void writeHeader() throws IOException { byte[] bytes = DbfMetadataUtils.toByteArrayHeader(metadata); // assert(bytes.length == 16); out.write(bytes); BitUtils.memset(bytes, 0); out.write(bytes);

cooldemo commented 8 years ago

jdbf.zip example.zip

Hi, I have made quite a few changes to it. I don't know if you will be able to create new files, but it should work on appending to existing files as well as reading them.

I have attached fixed sources and part of my code as an example how to use it.

laptio commented 8 years ago

Thank you alot!!! I found the main reason. It's necessary to add number of rows and maybe necessary , I'm not sure, to add the date. You do it in your example here: dbfMetaFakvy.setRecordsQty(billCount); dbfMetaFakvy.setUpdateDate(Calendar.getInstance().getTime());