检查文件是否存在于机器人的资产文件夹? [英] Check for file existence in androids assets folder?

查看:170
本文介绍了检查文件是否存在于机器人的资产文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序具有.TXT在资产文件夹中的子目录的文件。它读取的txt文件,并把它们放入一个TextView。它是伟大的工作,而没有任何问题。

My app has .txt files in subdirectories in the assets folder. It reads those .txt files and puts them in a textview. It's working great and no problems.

我应该关心用户或丢失的文件夹入门删除了资产的文件。如果以往任何时候都可能发生,我的应用程序会得到一个错误,因为该文件将不会有当它试图读取到的数据流。

Should I be concerned about the files in the assets folder getting deleted by the user or missing. If this ever could happen, my app would get an error because the file would not be there when it tried to read it into the stream.

是否有必要对我来说,检查资产文件是否存在之前,我读它还是资产管理采取的一切照顾?我也想知道,如果有一个机会,一个用户会或可能会删除和资产文件。

Is there a need for me to check the existence of an asset file before I read it or does the asset manager take care of it all? I also was wondering if there's a chance that a user would or could delete and asset file.

就像我说的,一切正常,没有我插入code,以检查文件是否存在。我只是想知道,如果人们使用.exists()语句每次他们去阅读从资产运转时间。

Like I say, everything works fine without me inserting code to check for file existence. I just wondered if people use the .exists() statement every time they go to read in a stream from assets.

推荐答案

Yes和No.普通用户将无法将其删除,但有根的手机用户,谁不知道他们在做什么。 ......那是一个不同的情况。

Yes and No. A normal user would not be able to delete them, but a user on a rooted phone who doesn't know what they're doing... thats a different situation.

如果你问我额外的code是不需要​​的。此外,如果你尝试不存在,你会得到扔在某些时候异常开放的文件,赶上并显示一个对话框,如果你真的想。

If you ask me the extra code is not needed. Also if you try an open a file that doesn't exist you will get an exception thrown at some point, catch that and display a dialog if you REALLY want to.

这篇关于检查文件是否存在于机器人的资产文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆