1
public static String openAssetFile(Context ctx) {


BufferedReader br=new BufferedReader(new InputStreamReader(ctx.getResources().openRawResource(R.raw.hung)));
String readLine;
String sout="";

    try {
        while ((readLine = br.readLine()) != null) {
            sout+=readLine;
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


return sout;
}

这不起作用,它冻结了,我的 xml 文件大约 300 kb。

我怎么能处理这个?

4

2 回答 2

1

尝试使用这样的 StringBuffer,你这样做的方式很慢

public static String openAssetFile(Context ctx) {
    BufferedReader br=new BufferedReader(new InputStreamReader(
          ctx.getResources().openRawResource(R.raw.hung)));
    String readLine;
    StringBuffer sout= new StringBuffer();

    try {
        while ((readLine = br.readLine()) != null) {
            sout.append(readLine);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
   return sout.toString();
}
于 2011-04-06T21:11:38.947 回答
0

尝试将其放入“/xml”并调用Resources.getXML(),还是将其放入“/assets”?

于 2011-01-24T12:43:23.643 回答