当前位置:操作系统 > 安卓/Android >>

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 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,