* added file create helper function

This commit is contained in:
Reinhard Pointner 2015-03-25 05:36:29 +00:00
parent c3895a5852
commit e08fd8799b
2 changed files with 9 additions and 8 deletions

View File

@ -243,6 +243,10 @@ public class ScriptShellMethods {
return FileUtilities.copyAs(self, new File(destination, self.getName())); return FileUtilities.copyAs(self, new File(destination, self.getName()));
} }
public static void createFileIfNotExists(File self) throws IOException {
FileUtilities.createFileIfNotExists(self);
}
public static File relativize(File self, File other) throws IOException { public static File relativize(File self, File other) throws IOException {
return self.getCanonicalFile().toPath().relativize(other.getCanonicalFile().toPath()).toFile(); return self.getCanonicalFile().toPath().relativize(other.getCanonicalFile().toPath()).toFile();
} }

View File

@ -156,15 +156,12 @@ public final class FileUtilities {
return org.apache.commons.io.FileUtils.deleteQuietly(file); return org.apache.commons.io.FileUtils.deleteQuietly(file);
} }
public static File createFileIfNotExists(File file) throws IOException { public static void createFileIfNotExists(File file) throws IOException {
if (file.isFile()) { if (!file.isFile()) {
return file; // create parent folder structure if necessary & create file
}
// create parent folder structure if necessary
Files.createDirectories(file.getParentFile().toPath()); Files.createDirectories(file.getParentFile().toPath());
// create file Files.createFile(file.toPath()).toFile();
return Files.createFile(file.toPath()).toFile(); }
} }
public static byte[] readFile(File source) throws IOException { public static byte[] readFile(File source) throws IOException {