을 가져올 실제 파일 경로로하여 onActivityResult에서 URI를 변환합니까하지만 File file = new File(path)
을 쓸 때 그것은 FileNotFoundException
가 발생합니다. 도와주세요.어떻게 <code>/document/primary:Download/West Delhi Mis June.xlsx</code></p> <p>으로 내가 <code>String path = uri.getPath()</code>에서 URI를 얻고 해당 파일
public void getdata(File fil){
try{
Workbook w;
w = Workbook.getWorkbook(fil);
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);
Cell c3 = sheet.getCell(2,j);
Cell c4 = sheet.getCell(3,j);
Cell c5 = sheet.getCell(4,j);
Cell c6 = sheet.getCell(5,j);
Cell c7 = sheet.getCell(6,j);
Cell c8 = sheet.getCell(7,j);
Cell c9 = sheet.getCell(8,j);
Cell c10 = sheet.getCell(9,j);
Cell c11 = sheet.getCell(10,j);
Cell c12 = sheet.getCell(11,j);
Cell c13 = sheet.getCell(12,j);
String date = c1.getContents();
String empid = c2.getContents();
String project = c3.getContents();
String name = c4.getContents();
String route = c5.getContents();
String cabno = c6.getContents();
String location = c7.getContents();
String contact = c8.getContents();
String gender = c9.getContents();
String duty = c10.getContents();
String shift = c11.getContents();
String cabtype = c12.getContents();
String zone = c13.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.openxmlformats-officedocument.spreadsheetml.sheet");
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 path = uri.getPath();
InputStream dataStream = this.getContentResolver().openInputStream(path);
}
}
}
uri를 어떻게 받고 있습니까? – codeFreak
":"을 "/"로 바꾸고 path.replace (":", "/"); – Gautam
안드로이드 파일 선택기를 통해 @codeFreak – user6698813