From a836410cbd3538299c0849a3b4cd10361bdca2ab Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 8 Jan 2024 11:56:24 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=ABSt?= =?UTF-8?q?ring=E3=82=92=E4=BF=9D=E5=AD=98=E3=81=99=E3=82=8B=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/file/impl/FileManagerImpl.java | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 2173d35b..cd442e92 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -175,14 +175,46 @@ public class FileManagerImpl implements FileManager { } @Override - public void saveText(String text, String fileName) { - createFile(fileName); + public void saveText(String text, String fileName) { // TODO-rca: リファクタリング // TODO-rca: 統合 + if (isExist(fileName)) { + logger.debug("saveText", "file already exists"); + // Overwrite + try { + Files.write(currentDir.resolve(fileName), text.getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } + else { + try { + Files.createFile(currentDir.resolve(fileName)); + Files.write(currentDir.resolve(fileName), text.getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } } @Override public void saveText(String text, Path path) { - + if (isExist(path)) { + logger.debug("saveText", "file already exists"); + // Overwrite + try { + Files.write(path, text.getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } + else { + try { + Files.createFile(path); + Files.write(path, text.getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } } @Override