Android Question SDK 33 - No Such File or Directory - DirAssets copy

Arf

Well-Known Member
Licensed User
Longtime User
I've been making a SDK 33 compatible version of my app on a Galaxy Tab A7 Lite with Android 13, all seems working fine.
I have just run it on a Xiaomi Pad5 with Android 13 and I am getting an error when copying a PDF from my assets folder to AppFolder, which is:
B4X:
Dim AppFolder As String = File.DirInternal & "/My AppName"

The error is:
B4X:
Error occurred on line: 538 (Main)
java.io.FileNotFoundException: /data/user/0/com.msolutions.myappname/files/My AppName/002.INSTRUCT.pdf: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:574)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
    at anywheresoftware.b4a.objects.streams.File.Copy(File.java:342)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
    at anywheresoftware.b4a.BA$2.run(BA.java:395)
    at anywheresoftware.b4a.BA.setActivityPaused(BA.java:467)
    at com.msolutions.myappname.main$ResumeMessage.run(main.java:313)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:211)
    at android.os.Looper.loop(Looper.java:300)
    at android.app.ActivityThread.main(ActivityThread.java:8294)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8172)
    at libcore.io.IoBridge.open(IoBridge.java:560)
    ... 24 more

It happens in both release and debug, in the top of main I have: #DebuggerForceStandardAssets: true

Any ideas why? Thanks
 

DonManfred

Expert
Licensed User
Longtime User
HIDING the FULL Code you used is a good way not to get help

This works for me.
B4X:
    File.Copy(File.DirAssets,"imageorg.jpg",Starter.rp.GetSafeDirDefaultExternal("My AppName"),"imageorg.jpg")
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Oops, I did intend to paste the code in under the Appfolder fline but failed to! It is:
B4X:
If File.Exists(DDB.AppFolder, "002.INSTRUCT.pdf") Then File.Delete(DDB.AppFolder, "002.INSTRUCT.pdf")
File.Copy(File.DirAssets, "002.INSTRUCT.pdf", DDB.AppFolder, "002.INSTRUCT.pdf")

I know I am deleting the file then replacing it, this is because the new PDF is an updated version of the PDF that is potentially in the folder already.

I used to use DirRootExternal but am migrating it my storage location to DirInternal after reading external storage should not be used in SDK31 onwards.
 
Upvote 0
Top