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(); }
Android开发相关:读取原始资源
最新推荐文章于 2025-11-26 16:17:36 发布
本文介绍了一种从原始文件中读取字符串的方法,并详细解释了如何将输入流转换为字符串。
1495

被折叠的 条评论
为什么被折叠?



