mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-29 19:13:16 +00:00
ファイルの中身をStringで読み出すメソッド作成
This commit is contained in:
parent
52657fdbbd
commit
2ba243ea4a
|
@ -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);
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user