Android开发相关:(03)读取原始资源
[java] String getStringFromRawFile(Activity activity) throws IOException {Resources r = activity.getResources();
InputStream is = r.openRawResource(R.raw.test);
String myText = convertStreamToString(is);
is.close();
return myText;
}
String convertStreamToString(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = is.read();
while (i != -1) {
baos.write(i);
i = is.read();
}
return baos.toString();
}
摘自 horsttnann的专栏
补充:移动开发 , Android ,