我想读取SD卡中的csv文件,但是当我选择文件时,有一个文件不能被找到的异常。
代码如下:
Intent intent = new Intent();
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();
}
}}
我从这里获取的错误:"File f = new File(data.getPath());"
为什么会出现这个异常呢?