Android开发相关:(03)读取原始资源
2505 点击·0 回帖
![]() | ![]() | |
![]() | [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(); } | |
![]() | ![]() |