Made the directory build happen at write instead of read

This commit is contained in:
jsrobson10 2019-07-07 19:50:51 +10:00
parent 087b75fffe
commit 09ecdb27e4
1 changed files with 15 additions and 5 deletions

View File

@ -14,14 +14,18 @@ public class BdfFileManager extends BdfObject
private static BdfDatabase init(String path) private static BdfDatabase init(String path)
{ {
// Get the file handler // Get the file
File file = new File(path); File file = new File(path);
// Create the parent directories // Does the file have read access
file.getParentFile().mkdirs(); if(file.canRead())
{
// Return the files contents as a database
return new BdfDatabase(FileHelpers.readAllIgnoreErrors(path));
}
// Return the files contents as a database // Return an empty database if there is no read access
return new BdfDatabase(FileHelpers.readAllIgnoreErrors(path)); return new BdfDatabase();
} }
public BdfFileManager(String path) { public BdfFileManager(String path) {
@ -33,6 +37,12 @@ public class BdfFileManager extends BdfObject
{ {
try try
{ {
// Get the file handler
File file = new File(path);
// Create the parent directories
file.getParentFile().mkdirs();
// Get the database file for output // Get the database file for output
FileOutputStream out = new FileOutputStream(path); FileOutputStream out = new FileOutputStream(path);