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

this not work, its freezes, my xml file is about 300 kb.

how i can handle this?

lacas
  • 13,928
  • 30
  • 109
  • 183

2 Answers2

1

Try using a StringBuffer like this, the way you are doing it is very slow

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();
}
Jesse
  • 31
  • 3
0

Tried putting it in "/xml" and calling Resources.getXML(), or putting it in "/assets"?

Ken
  • 30,811
  • 34
  • 116
  • 155