我试图从我的应用程序中读取一个CSV文件,代码在Android 5.1以下完美地工作,但在我的Android 10手机上不工作。
这是在logcat上抛出的异常。
W/System.err: java.io.FileNotFoundException: /document/primary:RFS Site Project Related Tickets
Weekly Data as of 20200607.csv: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileInputStream.<init>(FileInputStream.java:159)
W/System.err: at java.io.FileReader.<init>(FileReader.java:72)
at com.example.noragdrive.MainActivity.openFileFromFilePicker(MainActivity.java:155)
at com.example.noragdrive.MainActivity.onActivityResult(MainActivity.java:74)
W/System.err: at android.app.Activity.dispatchActivityResult(Activity.java:8292)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5090)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5138)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7691)
at libcore.io.IoBridge.open(IoBridge.java:482)
... 17 more
我在这里得到一个异常
CSVReader dataRead = new CSVReader(new FileReader(file));
这是文件选取器。
Intent pickerIntent = mDriveServiceHelper.createFilePickerIntent();
pickerIntent.addCategory(Intent.CATEGORY_OPENABLE);
pickerIntent.setAction(Intent.ACTION_GET_CONTENT);
pickerIntent.setType("*/*");
// The result of the SAF Intent is handled in onActivityResult.
startActivityForResult(pickerIntent, REQUEST_CODE_OPEN_DOCUMENT);