2010-11-08 54 views
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。Android java資產 - >快

我該如何處理?

回答

0

試過把它放在「/ xml」中,然後調用Resources.getXML(),或者把它放在「/ assets」中?

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