[英]Android Delete Database programmatically: android.system.ErrnoException: chmod failed: EPERM (Operation not permitted)
[英]ErrnoException: open failed: EPERM (Operation not permitted) in samsung android
我只是寫入在內部存儲中創建的文件。 它在大多數設備上都可以正常工作,但奇怪的是它不適用於Android 11 版本的三星設備。
我正在使用所有三個權限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
android:minSdkVersion="30"/>
下面是我寫入文件的代碼部分:
val oldfile = File(oldBasePath)
val fiStream = FileInputStream(oldfile)
var outputFile = File(appFolder, fileName)
var fos = FileOutputStream(outputFile)
val buf = ByteArray(1024)
var len: Int
do {
len = fiStream.read(buf)
if (len > 0) {
fos?.write(buf, 0, len)
} else {
break
}
} while (true)
fiStream.close()
fos?.close()
在這里,我在第二行代碼中遇到錯誤。 下面是logcat:
Non-fatal Exception: java.io.FileNotFoundException: /storage/emulated/0/MyFileStore/Röst-inspelning.txt: open failed: EPERM (Operation not permitted)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at com.test.ui.FileListFragment.saveFileApps(FileListFragment.java:729)
at com.test.ui.FileListFragment.access$saveFileApps(FileListFragment.java:50)
at com.test.ui.FileListFragment$loadAppFiles$1$result1$1.invokeSuspend(FileListFragment.java:541)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)
Caused by android.system.ErrnoException: open failed: EPERM (Operation not permitted)
at libcore.io.Linux.open(Linux.java)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8494)
at libcore.io.IoBridge.open(IoBridge.java:478)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at com.test.ui.FileListFragment.saveFileApps(FileListFragment.java:729)
at com.test.ui.FileListFragment.access$saveFileApps(FileListFragment.java:50)
at com.test.ui.FileListFragment$loadAppFiles$1$result1$1.invokeSuspend(FileListFragment.java:541)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)
下面是我寫入文件的代碼部分:
但是我們看不到你想在哪里寫文件。
非致命異常:java.io.FileNotFoundException:/storage/emulated/0/MyFileStore/Röst-inspelning.txt:打開失敗:EPERM(不允許操作)`
現在我們知道您在外部存儲上使用了一個位置,您的應用程序無法在 Android 11 上寫入。
一切從那個不能創建的目錄開始
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.