Android java从assets->fast中打开

发布于 2024-10-01 15:45:16 字数 505 浏览 0 评论 0原文

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。

我该如何处理这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你不是我要的菜∠ 2024-10-08 15:45:16

尝试使用这样的 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();
}

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();
}
埖埖迣鎅 2024-10-08 15:45:16

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文