【发布时间】:2011-10-07 09:10:26
【问题描述】:
我正在尝试制作一个简单的 android 应用程序,该应用程序基本上会导入一个 csv 并将其插入到我的数据库表中。到目前为止,我能够读取 res 文件夹中的 csv 文件。
我的示例 csv 文件名为“test.csv”,基本上是通过“InputStream is = this.getResources().openRawResource(R.drawable.test);”访问的。
这是我的示例代码:
InputStream is = this.getResources().openRawResource
(R.drawable.test);
BufferedReader reader = new BufferedReader(new InputStreamReader
(is));
try {
String line;
String brand = "";
String model = "";
String type = "";
this.dh = new DataHelper(this);
//this.dh.deleteAllCar();
while ((line = reader.readLine()) != null) {
// do something with "line"
String[] RowData = line.split(",");
brand = RowData[1];
model = RowData[2];
type = RowData[3];
this.dh = new DataHelper(this);
//this.dh.deleteAllCar();
this.dh.insertcsv(brand, model, type);
}
}catch (IOException ex) {
// handle exception
}finally {
try {
is.close();
}
catch (IOException e) {
// handle exception
}
}
这很好用,但是,我希望能够创建一个功能,用户可以指定从哪里获取文件(例如从手机的 sdcard 等)。但现在,我想知道如何从 sdcard(mnt/sdcard/test.csv) 访问 csv。
我们将不胜感激!谢谢,编码愉快!
【问题讨论】: