Possible Duplicate:
reading a specific file from sdcard in android
I'm trying to make a simple android app that basically imports a csv and inserts it to my database table. So far, I was able to read a csv file inside the res folder.
my sample csv file is named "test.csv" and is basically accessed through "InputStream is = this.getResources().openRawResource(R.drawable.test);".
Here's my sample code:
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
}
}
This works fine however, I want to be able to make a feature wherein the user can specify where to get the file(like from phone's sdcard, etc). But for now, I wanted to know how to access the csv from sdcard(mnt/sdcard/test.csv).
Help will be highly appreciated! thanks and happy coding!