goback add

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();
}


喜欢0 评分0