2019年10月28日 星期一

各種讀取的方法


        //將傳入的textFile檔案轉成字串
public String fileToString(String textFile, String charEncoding) throws Exception {
String msg = "";
try (
InputStream fis = context.getResourceAsStream(textFile);
InputStreamReader isr = new InputStreamReader(fis, charEncoding);
CharArrayWriter caw = new CharArrayWriter();
) {
char[] c = new char[8192];
int len = 0;
while ((len = isr.read(c)) != -1) {
caw.write(c, 0, len);
}
msg = caw.toString();
}
return msg;
}

沒有留言:

張貼留言

無暇的程式碼(Clean code)金句

The only valid measurement of code quality: WTFs/minute.