From 2ba243ea4a8a7b520a365a608e3a67c90bc94761 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 8 Jan 2024 11:48:17 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E4=B8=AD=E8=BA=AB=E3=82=92String=E3=81=A7=E8=AA=AD=E3=81=BF?= =?UTF-8?q?=E5=87=BA=E3=81=99=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/file/FileManager.java | 3 +++ .../source/file/impl/FileManagerImpl.java | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index f620f239..dcc21e52 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -26,6 +26,9 @@ public interface FileManager { File getFile(String fileName); File getFile(Path path); + String loadText(String fileName); + String loadText(Path path); + boolean isExist(Path path); boolean isExist(String fileName); 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 7a25adef..92a4af70 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 @@ -3,6 +3,7 @@ package one.nem.lacerta.source.file.impl; import android.graphics.Bitmap; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -149,6 +150,30 @@ public class FileManagerImpl implements FileManager { return path.toFile(); } + @Override + public String loadText(String fileName) { + try(FileInputStream fileInputStream = new FileInputStream(currentDir.resolve(fileName).toFile())) { + byte[] bytes = new byte[fileInputStream.available()]; + fileInputStream.read(bytes); // TODO-rca: エラーハンドリング + return new String(bytes); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public String loadText(Path path) { + try(FileInputStream fileInputStream = new FileInputStream(path.toFile())) { + byte[] bytes = new byte[fileInputStream.available()]; + fileInputStream.read(bytes); // TODO-rca: エラーハンドリング + return new String(bytes); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + @Override public boolean isExist(Path path) { logger.debug("isExist", "called");