Monday 28 February 2022

ErrnoException: open failed: ENOENT (No such file or directory) in android

I am simply writing into a file that is created in internal storage. It's working fine on most of the devices but strangely it's not working on a few devices.

I am using all three permissions:

<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"/>

Below is my code part for writing into file:

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()

Here I am getting error in 2nd line of code. Below is the logcat:

Non-fatal Exception: java.lang.Exception: java.io.FileNotFoundException: /data/app/~~g6QIOWSCR57wvCe1sS-znA==/com.whatsapp-UV9OLmiceKxlpMCN9VkZ0A==/base.apk: open failed: ENOENT (No such file or directory)
       at com.test.helpers.Applog.e(Applog.kt:22)
       at com.test.ui.FileListFragment.catchErrorFromSaveApk(FileListFragment.kt:413)
       at com.test.ui.FileListFragment.saveApkApps(FileListFragment.kt:388)
       at com.test.ui.FileListFragment.access$getSessionManager$p(FileListFragment.kt:35)
       at com.test.ui.FileListFragment$loadAppFiles$1$result1$1.invokeSuspend(FileListFragment.kt:191)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)


Caused by android.system.ErrnoException: open failed: ENOENT (No such file or directory)
       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:8517)
       at libcore.io.IoBridge.open(IoBridge.java:478)
       at java.io.FileInputStream.<init>(FileInputStream.java:160)
       at com.test.ui.FileListFragment.saveApkApps(FileListFragment.kt:359)
       at com.test.ui.FileListFragment.access$getSessionManager$p(FileListFragment.kt:35)
       at com.test.ui.FileListFragment$loadAppFiles$1$result1$1.invokeSuspend(FileListFragment.kt:191)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)


from ErrnoException: open failed: ENOENT (No such file or directory) in android

No comments:

Post a Comment