Android AssetManager/InputStream 异常
做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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
终于想通了。明显的用户错误,只见树木不见森林。 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.
也许你可以这样使用
maybe you can use like this