Made missing directories get created automatically
This commit is contained in:
parent
331f820c60
commit
087b75fffe
|
@ -9,7 +9,7 @@ public class Main {
|
|||
public static void main(String[] args)
|
||||
{
|
||||
|
||||
BdfFileManager file = new BdfFileManager("db.bdf");
|
||||
BdfFileManager file = new BdfFileManager("test/test2/db.bdf");
|
||||
|
||||
|
||||
file.setArray(new BdfArray());
|
||||
|
@ -18,7 +18,7 @@ public class Main {
|
|||
file.saveDatabase();
|
||||
|
||||
|
||||
BdfFileManager file2 = new BdfFileManager("db.bdf");
|
||||
BdfFileManager file2 = new BdfFileManager("test/test2/db.bdf");
|
||||
System.out.println(file2.getArray().get(0).getString());
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package bdf.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import bdf.data.BdfDatabase;
|
||||
|
@ -12,8 +12,20 @@ public class BdfFileManager extends BdfObject
|
|||
{
|
||||
protected String path;
|
||||
|
||||
private static BdfDatabase init(String path)
|
||||
{
|
||||
// Get the file handler
|
||||
File file = new File(path);
|
||||
|
||||
// Create the parent directories
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
// Return the files contents as a database
|
||||
return new BdfDatabase(FileHelpers.readAllIgnoreErrors(path));
|
||||
}
|
||||
|
||||
public BdfFileManager(String path) {
|
||||
super(new BdfDatabase(FileHelpers.readAllIgnoreErrors(path)));
|
||||
super(init(path));
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue