본문 바로가기

Tech develop/Android

[Android]html형식의 txt 파일 읽어오기

반응형
private Spanned readTxt(int textFileResId) {
if (textFileResId <= 0) {
return new SpannedString("");
}
String data = null;
InputStream inputStream = getContext().getResources().openRawResource(textFileResId);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1) {
byteArrayOutputStream.write(i);
i = inputStream.read();
}
data = new String(byteArrayOutputStream.toByteArray(), "UTF-8");
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return Html.fromHtml(data);
}
view raw ReadTextFile hosted with ❤ by GitHub
반응형