如何查看Android Asset资源?
我想检查 /assets/ 文件夹中是否存在文件。 我怎样才能做到呢?请帮忙。
I want to check, whether a file exists or not in the /assets/ folder.
How could I do it? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我向我的应用程序类之一添加了一个辅助方法。我假设;
List
并不占用内存(我的应用程序中只有 78 个资源)。I added a helper method to one of my application classes. I'm assuming that;
List<String>
isn't a memory hog (only 78 assets in my app).您也可以尝试打开流,如果失败,则文件不存在,如果没有失败,文件应该存在:
You could also just try to open the stream, if it fails the file is not there and if it does not fail the file should be there:
您可以使用 Resources.openRawResourceFd(int resId)
http ://developer.android.com/reference/android/content/res/Resources.html#openRawResourceFd%28int%29
You can use Resources.openRawResourceFd(int resId)
http://developer.android.com/reference/android/content/res/Resources.html#openRawResourceFd%28int%29
您必须自己进行检查。据我所知,这项工作没有方法。
You have to perform your own checks. As I know, there is no method for this job.