final RandomAccessFile myFile;
FileContext(final File file) throws IOException {
+ final File parentFile = file.getParentFile();
+ if (!parentFile.exists()) parentFile.mkdirs();
myFile = FileUtilRt.doIOOperation(new FileUtilRt.RepeatableIOOperation<RandomAccessFile, IOException>() {
@Nullable
@Override
try {
return new RandomAccessFile(file, RW);
} catch (FileNotFoundException ex) {
- if (!file.getParentFile().exists()) {
- throw new IOException("Parent file doesn't exist:" + file);
+ if (!parentFile.exists()) {
+ throw new IOException("Parent file still doesn't exist:" + file);
}
if (!finalAttempt) return null;
throw ex;
final File lengthFile = getLengthFile();
DataOutputStream stream = null;
try {
+ File parentFile = lengthFile.getParentFile();
+ if (!parentFile.exists()) parentFile.mkdirs();
stream = FileUtilRt.doIOOperation(new FileUtilRt.RepeatableIOOperation<DataOutputStream, IOException>() {
@Nullable
@Override
return new DataOutputStream(new FileOutputStream(lengthFile));
} catch (FileNotFoundException ex) {
if (!lengthFile.getParentFile().exists()) {
- throw new IOException("Parent file doesn't exist:" + lengthFile);
+ throw new IOException("Parent file still doesn't exist:" + lengthFile);
}
if (!lastAttempt) return null;
throw ex;