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");