Android 中 CSV 文件的位置
我在 Android 应用程序中读取 .CSV 文件时遇到问题。主要是“FileNotFound”错误。放置文件最容易的位置在哪里,以及它的地址是什么。我一直在几个不同的地方闲逛,但没有运气。
有人能指出我正确的方向吗?
I'm having trouble reading in from a .CSV file in an android app. Mainly a "FileNotFound" error. Where would be the easiest place to put the file, and what would be the address to it. I have been messing around with a few different places but have had no luck.
Can anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望将其存储在可移动存储(SD 卡)上。首先,您需要检查存储是否可用,然后进行读/写。
该文档对此有一些注释: http:// /developer.android.com/intl/de/guide/topics/data/data-storage.html#filesExternal
(注意那里的 API 级别 8 的东西,例如 getExternalFilesDir,我还没有使用过它,但看起来很方便,如果你能保证 >=8。)
你可以检查存储是否在那里例如:
如果不存在,则显示一个Toast(至少)或以其他方式让用户知道。
然后读起来就像:
然后你可以使用常规的File方法来检查它是否存在,是否可读等,然后使用它。
另请注意,文档建议您使用 SD 卡上的位置,例如“Android/data//files”,这是一个合理的建议,但许多应用程序只使用“/appname/”等。
还有一件事,当然,您只需安装 SD 卡并创建该结构并复制文件即可将文件放在那里。或者,您也可以通过编程方式(从您的应用程序)执行此操作,但听起来您已经拥有该文件,并且只想读取它。
You'll probably want it on the removable storage (SD card). First you'll want to check if the storage is available, then read/write.
The docs have some notes on this: http://developer.android.com/intl/de/guide/topics/data/data-storage.html#filesExternal
(Note the API level 8 stuff there, such as getExternalFilesDir, I haven't used that yet, but looks handy, if you can guarantee >=8.)
You can check if storage is there with something like:
If it's not there show a Toast (at a minimum) or otherwise let the user know.
Then read it like:
Then you can use the regular File methods to check if it's there, it's readable, etc., and then use it.
Also note that the docs recommend you use a location on the SD card like "Android/data//files", and that's a reasonable recommendation, but many apps just use "/appname/" or such.
And -- one more thing, you can put the file there just by mounting the SD card and creating that structure and copying a file over, of course. Alternatively, you could do that programatically (from your app) as well, but it sounds like you already have the file, and just want to read it.