Android Question File not found in Assets

Cadenzo

Active Member
Licensed User
Longtime User
How can that be, that I get a list of files in Assets, than the exception, that the file does not exist?
(Exception) java.lang.Exception: java.io.FileNotFoundException: /data/user/0/de.cadenzo.klarinette/files/virtual_assets/tonarten_lernen.html (No such file or directory)

B4X:
Sub CopyFromAssets
    Dim sMainFolder As String = xui.DefaultFolder
    Dim sFolderA As String = File.DirAssets
    Dim sFolderB As String = File.Combine(sMainFolder, "data")
    If File.Exists(sMainFolder, "data") = False Then File.MakeDir(sMainFolder, "data")
    For Each sFile As String In File.ListFiles(sFolderA)
        If sFile.EndsWith("html") Then 'Or sFile.EndsWith(".jpg") Then
            Try
                File.Copy(sFolderA, sFile, sFolderB, sFile)
            Catch
                Log(sFile)
                Log(LastException)
            End Try
        End If
    Next
End Sub
 

toby

Well-Known Member
Licensed User
Longtime User
Try:
B4X:
Dim sFolderB As String = sMainFolder &  "/data"

File.Combine is used to combine a folder with a filename.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
The file exists and in the next line it does not exist? This Error occurs in line 3
java.io.FileNotFoundException: /data/user/0/de.cadenzo.klarinette/files/virtual_assets/filestocopy.txt (No such file or directory)

B4X:
Sub CopyFromAssets
    If File.Exists(File.DirAssets, "FilesToCopy.txt") Then
        Dim sFile As String = File.ReadString(File.DirAssets, "FilesToCopy.txt")
        'Dim liFiles As List = File.ReadList(File.DirAssets, "FilesToCopy.txt")
...
    End If
End Sub
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
The file exists and I get no IDE warning, that the file is missing from the files tab. So why I can not read it? I already tried: File Manager "Sync", Tools "Clean Files Folder", "Clean Project", I also tried to add the file on different ways, in Shared Folder, with "Add Files"...
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Now, after many tests this strange situation, when I test with a file "FilesToCopy.txt":
-I removed this file in the IDEwith "Remove", it does not exist on the Files Manager Tab, also not after Synch
-it is also not in the Files folder
-I removed this file also from the folder sharedFiles and removed the line
-I removed the '#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
-I tried Tools "clean project" and started it new
The file definitely does not exist in the project, also the IDE says so But:
With my code in Post 4 The file exists and I can even read it now and it shows the text in the file, but from where???
I never had such a strange problem :-(
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Now I copy the text to a new File: "_FilesToCopy.txt" with the first "_", add it to the Files Manager Tab and here File.Exists(File.DirAssets, "_FilesToCopy.txt") returns fals, but the file "FilesToCopy.txt" that really not exists returns true. Should I give up?
 
Upvote 0
Top