Fixed error in FileUtils when creating a new File with append = true.
In this case FileUtils throws a FileCreationException if the path for the new file doesn't already exist, because it doesn't try to create the path. TestCase appendend to FileUtilsTests testCreateDirectoryStructureAppendMode checks that a path is creaded if append is true
This commit is contained in:
committed by
Michael Minella
parent
3ea8d3ed65
commit
7c9396da18
@@ -74,6 +74,9 @@ public final class FileUtils {
|
||||
}
|
||||
else {
|
||||
if (!file.exists()) {
|
||||
if (file.getParent() != null) {
|
||||
new File(file.getParent()).mkdirs();
|
||||
}
|
||||
if (!createNewFile(file)) {
|
||||
throw new ItemStreamException("Output file was not created: [" + file.getAbsolutePath()
|
||||
+ "]");
|
||||
|
||||
@@ -109,6 +109,29 @@ public class FileUtilsTests {
|
||||
dir1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the directories on the file path do not exist, they should be created
|
||||
* This must be true also in append mode
|
||||
*/
|
||||
@Test
|
||||
public void testCreateDirectoryStructureAppendMode() {
|
||||
File file = new File("testDirectory/testDirectory2/testFile.tmp");
|
||||
File dir1 = new File("testDirectory");
|
||||
File dir2 = new File("testDirectory/testDirectory2");
|
||||
|
||||
try {
|
||||
FileUtils.setUpOutputFile(file, false, true, false);
|
||||
assertTrue(file.exists());
|
||||
assertTrue(dir1.exists());
|
||||
assertTrue(dir2.exists());
|
||||
}
|
||||
finally {
|
||||
file.delete();
|
||||
dir2.delete();
|
||||
dir1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadFile(){
|
||||
|
||||
Reference in New Issue
Block a user