Skip to content

Commit f59e9c1

Browse files
committed
exporter test fix
1 parent a1b5c38 commit f59e9c1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

nitrite/src/main/java/org/dizitart/no2/tool/Exporter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ public void exportTo(String file) {
9494
*/
9595
public void exportTo(File file) {
9696
try {
97+
if (file.isDirectory()) {
98+
throw new IOException(file.getPath() + " is not a file");
99+
}
100+
101+
File parent = file.getParentFile();
102+
// if parent dir does not exists, try to create it
103+
if (!parent.exists()) {
104+
boolean result = parent.mkdirs();
105+
if (!result) {
106+
throw new IOException("Failed to create parent directory " + parent.getPath());
107+
}
108+
}
97109
exportTo(new FileOutputStream(file));
98110
} catch (IOException ioe) {
99111
throw new NitriteIOException(

0 commit comments

Comments
 (0)