Android Question File.Copy does not seem to work

sdixon

Member
Licensed User
Longtime User
Worked fine in v5.8, upgraded to v6 and now suddenly with the following code

B4X:
If File.Exists(File.DirAssets, Starter.msSQLFileName) Then
            File.Copy(File.DirAssets, Starter.msSQLFileName, File.DirDefaultExternal, Starter.msSQLFileName)
          End If

It checks to see if the file exists, which it does, then when it goes to copy the file I get the following

B4X:
** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:com.unicornsystemz.totalbeautychat
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 72 (Main)
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.unicornsystemz.totalbeautychat/files/totalbeautychat.sqlite: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:452)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:370)
    at anywheresoftware.b4a.objects.streams.File.Copy(File.java:336)
    at com.unicornsystemz.totalbeautychat.main._activity_create(main.java:440)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at com.unicornsystemz.totalbeautychat.main.afterFirstLayout(main.java:102)
    at com.unicornsystemz.totalbeautychat.main.access$000(main.java:17)
    at com.unicornsystemz.totalbeautychat.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7229)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Posix.open(Native Method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
    at libcore.io.IoBridge.open(IoBridge.java:438)
    ... 20 more
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

Is this a bug in v6 or am I doing something wrong?

Thanks
 

sdixon

Member
Licensed User
Longtime User
Foolishly set android:targetSdkVersion="23" and didn't realize I needed run-time permissions. And so we learn :)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

sdixon

Member
Licensed User
Longtime User
Thanks, I did that and it worked.
 
Upvote 0
Top