/** read-only channel access mode */
public static final OpenOption[] RO_CHANNEL_OPTS =
{StandardOpenOption.READ};
- /** read/write channel access mode */
+ /** read/write channel access mode for existing files */
public static final OpenOption[] RW_CHANNEL_OPTS =
{StandardOpenOption.READ, StandardOpenOption.WRITE};
+ /** read/write/create channel access mode for new files */
+ public static final OpenOption[] RWC_CHANNEL_OPTS =
+ {StandardOpenOption.READ, StandardOpenOption.WRITE,
+ StandardOpenOption.CREATE};
/** Name of the system object that is the parent of all tables */
private static final String SYSTEM_OBJECT_NAME_TABLES = "Tables";
readOnly |= !Files.isWritable(mdbFile);
// open file channel
- channel = openChannel(mdbFile, readOnly);
+ channel = openChannel(mdbFile, readOnly, false);
closeChannel = true;
}
boolean closeChannel = false;
if(channel == null) {
- channel = openChannel(mdbFile, false);
+ channel = openChannel(mdbFile, false, true);
closeChannel = true;
}
* that name cannot be created, or if some other error occurs
* while opening or creating the file
*/
- static FileChannel openChannel(Path mdbFile, boolean readOnly)
+ static FileChannel openChannel(
+ Path mdbFile, boolean readOnly, boolean create)
throws IOException
{
- OpenOption[] opts = (readOnly ? RO_CHANNEL_OPTS : RW_CHANNEL_OPTS);
+ OpenOption[] opts = (readOnly ? RO_CHANNEL_OPTS :
+ (create ? RWC_CHANNEL_OPTS : RW_CHANNEL_OPTS));
return FileChannel.open(mdbFile, opts);
}