在Android的CSV文件位置 [英] Locations of CSV files in Android

查看:173
本文介绍了在Android的CSV文件位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从.CSV文件中读取在Android应用程序。主要是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?

推荐答案

您可能会想它的可移动存储(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.

该文档有一些注意事项如下:的http://developer.android.com/intl/de/guide/topics/data/data-storage.html#filesExternal
(注API级别8的东西在那里,比如 getExternalFilesDir 的,我没有使用过该还,但看起来很方便,如果你能保证> = 8)。

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:

public boolean isExternalStorageAvail() {
      return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
   }

如果它不存在显示的吐司的(至少)或以其他方式让用户知道。

If it's not there show a Toast (at a minimum) or otherwise let the user know.

然后阅读它像:

File f = new File(Environment.getExternalStorageDirectory() + "/mycsvlocation/myfile.csv");

然后就可以使用常规的文件的方法来检查,如果它的存在,它是可读的,等等,然后使用它。

Then you can use the regular File methods to check if it's there, it's readable, etc., and then use it.

另外请注意,该文档推荐你喜欢的Android /数据文件//在SD卡上使用的位置,这是一个合理的建议,但许多应用程序只使用/ APPNAME /或这样的。

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.

和 - 一件事,你可以通过安装SD卡并创建结构,在复制文件,当然那里的文件。或者,你能做到这一点编程(从您的应用程序)为好,但它听起来像你已经拥有的文件,只是想读它。

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.

这篇关于在Android的CSV文件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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