아래 코드는 API 레벨 19에서 잘 작동하며 경로는 /storage/downloads/w.xls 으로 표시됩니다. API 수준의 오류 26.파일이 발견되지 않음 Android 파일의 예외 Kitkat에서 제대로 작동하는 동안
제발, 어떻게 해결합니까?
java.io.FileNotFoundException: /document/primary:Download/W.xls (No such file or directory)
public void getdata(String filestring){
try{
File file = new File(filestring);
Workbook w;
w = Workbook.getWorkbook(file);
Sheet sheet = w.getSheet(0);
for (int j = 1; j<sheet.getRows(); j++){
Cell c1 = sheet.getCell(0,j);
Cell c2 = sheet.getCell(1,j);
String date = c1.getContents();
String empid = c2.getContents();
adb.insertRoastData(date,empid,project,name,route,cabno,location,contact,gender,duty,shift,cabtype,zone);
}
}catch (Exception e){
e.printStackTrace();
}
}
public void performFileSearch() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/vnd.ms-excel");
startActivityForResult(intent, READ_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri uri = null;
if (resultData != null) {
uri = resultData.getData();
String filepath = getPath(uri);
getdata(filepath);
}
}
}
public String getPath(Uri uri) {
String path = null;
String[] projection = { MediaStore.Files.FileColumns.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if(cursor == null){
path = uri.getPath();
}
else{
cursor.moveToFirst();
int column_index = cursor.getColumnIndexOrThrow(projection[0]);
path = cursor.getString(column_index);
cursor.close();
}
return ((path == null || path.isEmpty()) ? (uri.getPath()) : path);
}
필요한 저장 권한이 있으며 런타임에 요청 했습니까? –
기존 경로가 없습니다. 당신이 보지마.? 내용 체계를 파일 경로로 변환하려고 시도하지 마십시오. 콘텐츠 스키마 자체를 사용하십시오. – greenapps
'w = Workbook.getWorkbook (file);'. File 개체를 나타내는 것으로 통합 문서를 만듭니다. 대신에 InputStream을 나타낼 가능성이 있습니까? – greenapps