I'm trying to import a CSV in my SQLite database on Android, using an intent to have the user choose the CSV file.
I get an ENOENT error on : FileReader file = new FileReader(fileName);
The file does exist since I get the path form an intent !
My manifest includes :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
My intent :
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/csv");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_CVS);
My onActivityResult(...) :
if (resultCode == RESULT_OK) {
File myPath_CSV = new File(data.getData().toString());
try {
myDb.importCSV(myPath_CSV);
} catch (IOException e) {
e.printStackTrace();
}
}
My importCSV(fileName) :
public void importOreilles(File fileName) throws IOException {
Log.w(TAG, fileName.toString());
FileReader file = new FileReader(fileName); // Getting an error !!!
BufferedReader buffer = new BufferedReader(file);
String line = null;
while ((line = buffer.readLine()) != null) {
String[] str = line.split(",");
insertOreille(str[0],str[1]); // Dealing with my database
}
}
The error I'm getting :
W/DBAdapter: file:/storage/emulated/0/Download/Oreilles.csv
W/System.err: java.io.FileNotFoundException: /file:/storage/emulated/0/Download/ABCDE.csv: open failed: ENOENT (No such file or directory)
I tried using getAbsolutePath, Uri, File... but I'm stuck.
Any help appreciated.