I am trying to read csv file which is located in SD card but when i select the file i get a File not found Exception.The below is my code.
Intent intent = new Intent(); //Browse the file
intent.setType("file/csv");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select csv"),
SELECT_CSV_Dialog);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
data = result.getData();//data is the URI
System.out.println("res "+data);
if (data.getLastPathSegment().endsWith("csv") || data.getLastPathSegment().endsWith("CSV")) {
try {
File f = new File(data.getPath());//this is where i get the file not found
FileInputStream fis =new FileInputStream(f);
fis = this.openFileInput(data.toString());
BufferedReader reader = new BufferedReader(
new InputStreamReader(fis));
String line;
while ((line = reader.readLine()) != null) {
String[] RowData = line.split(",");
System.out.println("row "+RowData.length);
if(RowData.length==2){
Toast.makeText(Importt.this, "Schema Supported", Toast.LENGTH_SHORT).show();
break;
}else{
Toast.makeText(Importt.this, "Schema not Supported", Toast.LENGTH_SHORT).show();
}
}}
This is where i get the error "File f = new File(data.getPath());".
Any suggestions are highly appreciated.