ファイルが存在しない場合に作成するメソッドを追加

This commit is contained in:
r-ca 2024-01-09 14:31:01 +09:00
parent 4cf3ff5f3c
commit 8913f8118d
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
2 changed files with 17 additions and 0 deletions

View File

@ -35,6 +35,8 @@ public interface FileManager {
// Create // Create
FileManager createFile() throws IOException; FileManager createFile() throws IOException;
FileManager createFile(String fileName) throws IOException; FileManager createFile(String fileName) throws IOException;
FileManager createFileIfNotExist() throws IOException;
FileManager createFileIfNotExist(String fileName) throws IOException;
FileManager createDirectory() throws IOException; FileManager createDirectory() throws IOException;
FileManager createDirectory(String directoryName) throws IOException; FileManager createDirectory(String directoryName) throws IOException;
FileManager createDirectoryIfNotExist() throws IOException; FileManager createDirectoryIfNotExist() throws IOException;

View File

@ -190,6 +190,20 @@ public class FileManagerImpl implements FileManager {
return this.createFile(); return this.createFile();
} }
@Override
public FileManager createFileIfNotExist() throws IOException {
if (!this.isExist()) {
this.createFile();
}
return this;
}
@Override
public FileManager createFileIfNotExist(String fileName) throws IOException {
this.resolve(fileName);
return this.createFileIfNotExist();
}
@Override @Override
public FileManager createDirectory() throws IOException { public FileManager createDirectory() throws IOException {
try { try {
@ -237,6 +251,7 @@ public class FileManagerImpl implements FileManager {
transformer.transform(source, result); transformer.transform(source, result);
} catch (Exception e) { } catch (Exception e) {
logger.error("saveXmlInternal", e.getMessage()); logger.error("saveXmlInternal", e.getMessage());
e.printStackTrace();
throw new IOException("Failed to save xml"); throw new IOException("Failed to save xml");
} }
} }