How do I read as a string an Android text file that is inside the Assets folder?
How do I read as a string an Android text file that is inside the Assets folder?
getAssets().open()
will return InputStream
.
Read it using the Java standard input and output (I / O) API. As in the following example:
StringBuilder buf=new StringBuilder();
InputStream json=getAssets().open("book/contents.json");
BufferedReader in=
new BufferedReader(new InputStreamReader(json, "UTF-8"));
String str;
while ((str=in.readLine()) != null) {
buf.append(str);
}
in.close();