Android AssetManager/InputStream 异常

发布于 2024-09-09 02:57:25 字数 668 浏览 3 评论 0原文

做Android 2.1开发。谁能向我解释为什么下面的代码会生成 IOException 并且不加载文件?这个确切的代码曾经有效,据我所知,它应该仍然有效。作为参考,Log.d() 命令正确列出了我期望的所有文件,并且这些文件被正确压缩到我的 .APK 文件中。

        AssetManager assetManager = mContext.getAssets();
        String[] files = null;
        try
            {
            files = assetManager.list("meshes");
            for (int i = 0; i < files.length; i++)
                Log.d(TAG, files[i]);
            InputStream is = assetManager.open(files[0]);
            }
        catch (IOException e) 
            {
            Log.e(TAG, "Could not load '" + e.getMessage()+ "'!");
            }

关于为什么现在会破裂有什么想法吗?我试图读取的文件是很小的(几个字节)二进制文件。

Doing Android 2.1 development. Can anybody explain to me why the following code generates a IOException and doesn't load the file? This exact code used to work, and as far as I can tell, it should still work. For reference, the Log.d() command correctly lists all files that I expect, and the files are correctly zipped into my .APK file.

        AssetManager assetManager = mContext.getAssets();
        String[] files = null;
        try
            {
            files = assetManager.list("meshes");
            for (int i = 0; i < files.length; i++)
                Log.d(TAG, files[i]);
            InputStream is = assetManager.open(files[0]);
            }
        catch (IOException e) 
            {
            Log.e(TAG, "Could not load '" + e.getMessage()+ "'!");
            }

Any ideas on why this breaks now? The files I'm trying to read are tiny (couple of bytes) binaries.

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

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

发布评论

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

评论(2

悲念泪 2024-09-16 02:57:25

终于想通了。明显的用户错误,只见树木不见森林。 list 命令不包含目录名,open 命令需要完整路径名。呃:) open 命令需要构建一个包含目录名和文件名的字符串。

Finally figured it out. Blatant user error, but couldn't see the forest for the trees. The list command doesn't include the directory name, the open command expects the full pathname. Duh :) The open command needs to build a string that includes both the directory name and the filename.

若有似无的小暗淡 2024-09-16 02:57:25

也许你可以这样使用

    AssetManager assetManager = this.getAssets();
    try{
            InputStream is = assetManager.open("tes.png");

            Log.d("Success", "Read");
    }catch (IOException e){
            Log.e("Failed", "Could not load '" + e.getMessage()+ "'!");
    }

maybe you can use like this

    AssetManager assetManager = this.getAssets();
    try{
            InputStream is = assetManager.open("tes.png");

            Log.d("Success", "Read");
    }catch (IOException e){
            Log.e("Failed", "Could not load '" + e.getMessage()+ "'!");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文