DANS-KNAW / dans-dbf-lib

DANS DBF Library
Apache License 2.0
14 stars 16 forks source link

Opening read only DBF file throws java.io.FileNotFoundException #1

Closed simoc closed 8 years ago

simoc commented 8 years ago

If my DBF file has write permission then it is opened successfully. However, if my DBF file is read-only, then the method Table.open() throws an java.io.FileNotFoundException. For example,

$ ls -l /tmp/sample.dbf 
-r--r--r-- 1 simoc simoc 225 Feb 26 20:23 /tmp/sample.dbf

the following Java code:

Table t = new Table(new File("/tmp/sample.dbf"));
t.open();

results in:

java.io.FileNotFoundException: /tmp/sample.dbf (Permission denied)
at java.io.RandomAccessFile.open0(Native Method)
at java.io.RandomAccessFile.open(RandomAccessFile.java:316)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)
at nl.knaw.dans.common.dbflib.Table.open(Table.java:273)
at nl.knaw.dans.common.dbflib.Table.open(Table.java:257)
at nl.knaw.dans.common.dbflib.Runner4.main(Runner4.java:12)
janvanmansum commented 8 years ago

Thanks for reporting this issue. Note that this library is no longer in active development, however we are accepting pull requests (if we agree with them, of course).

The issue results from the fact that we always open the file with "rw", here. That parameter could be made configurable, of course. If you do that, make sure that all the methods in the library that try to write to the dbf throw a clear exception, that makes it clear to the caller what is going wrong.

That said, an obvious work-around for you would be to first make a copy of sample.dbf that is also writable and then read from that copy. That is assuming that you cannot make the original sample.dbf writable for some reason.

simoc commented 8 years ago

I will create a pull request with my changes to enable read-only DBF files to be used.

simoc commented 8 years ago

2

janvanmansum commented 8 years ago

Thanks for contributing your patch :+1: