Android Question Why File.CopyAsync fails in debug mode but runs fine in release mode?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
B4X:
Sub GetStringFromFile(strFile As String) As ResumableSub
    
    Dim lBytes As Long
    Dim strResult As String
    
    If File.Exists(File.DirInternal, strFile) = False Then
        Wait For (File.CopyAsync(File.DirAssets, strFile, File.DirInternal, strFile)) Complete (bSuccess As Boolean)
        Log("bSuccess: " & bSuccess)
    End If
    
    'RAF is RandomAccessFile
    RAF.Initialize(File.DirInternal, strFile, True) 'fails in debug mode with java.io.FileNotFoundException:
                                                    '/data/user/0/b4a.exampleljjll/files/db_folder.txt: open failed: 
                                                    'ENOENT (No such file or directory)
    
    lBytes = RAF.Size

    'this will be a zero-based UTF8 byte array
    '-----------------------------------------
    Dim arrBytes(lBytes) As Byte
    RAF.ReadBytes(arrBytes, 0, lBytes, 0)
    
    strResult = BytesToString(arrBytes, 0, lBytes, "UTF-8")
    
    Return strResult
    
End Sub

RBS
 

Mahares

Expert
Licensed User
Longtime User
It definitely works in debug also. You code is correct. I would clean the project and clean file folder. Possibly uninstall the app and reinstall. There may be some stray files virtual in the assets folder skewing the compilation
 
Upvote 0
Top