Have some info, stored in a binary file ( like game levels, animation logic etc, never mind what ).
File is located in File.DirAssets, so it's a part of a package.
First, I was happy to know RandomAccessFile lib exist, but when i read manual, I realise it can't read files from APK, because its actually a ZIP file.
One solution is to copy the file to any other folder. The second solution is to read it to memory (if it is not too large) and then access the bytes array.
One solution is to copy the file to any other folder. The second solution is to read it to memory (if it is not too large) and then access the bytes array.
Sub ReadFile(Dir As String, FileName As String) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(100) 'size not really important
File.Copy2(File.OpenInput(Dir, FileName), out)
Return out.ToBytesArray
End Sub
Sub ReadFile(Dir As String, FileName As String) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(100) 'size not really important
File.Copy2(File.OpenInput(Dir, FileName), out)
Return out.ToBytesArray
End Sub
Assume, first 4 bytes are representation of some Int variable ( that is 4 bytes long ). So if i want to know this value, i need to calculate it from bytes:
I have a problem too with read/write file and or EncodeBase64/DecodeBase64
Can I ask somebody to explain what I missed?
I tried to encode the file on my side, and immediatelly decode back just for test. But the two file is significantly different!
What did I do wrong?
B4X:
Dim su As StringUtils
Dim out As OutputStream
Dim out2 As InputStream
Dim str1 As String
out.InitializeToBytesArray(1024)
File.Copy2(File.OpenInput(File.DirRootExternal, "sign18112401.png"), out)
str1=su.EncodeBase64(out.ToBytesArray)
out2.InitializeFromBytesArray(su.DecodeBase64(str1),0,str1.Length)
File.Copy2(out2,File.OpenOutput(File.DirRootExternal, "sign18112401_b.png",False))