String.GetBytes -> returns the bytes representing the string.
File.ReadBytes -> reads the file and return its raw content.
Practically:
B4X:
File.WriteString(s)
'same as
File.WriteBytes(s.GetBytes("utf8"))
Dim b() As Byte = s.GetBytes("utf8")
'same as
b = File.ReadBytes("file that we previously wrote")
Thanks again Erel,
Obvious when you know. GetBytes for Strings, ReadBytes for files. [EDIT: Maybe not so obvious.]
Unfortunately I still have basically the same problem but with ReadBytes. I must be formatting incorrectly but can't see the problem. ReadBytes (Dir As String, FileName As String) As Byte()
Or???
B4X:
Dim b() As Byte
b = File.ReadBytes("file that we previously wrote")
B4X:
Private Filename2 As String = "helpfile.htm"
Private HelpByte() As Byte = File.ReadBytes(File.DirAssets, Filename2)("UTF8")
Private in As InputStream
in.InitializeFromBytesArray(HelpByte, 0, HelpByte.Length)
This code Logs the following:
Main - 7072: Cannot cast type: {Type=String,Rank=0, RemoteObject=True} to: {Type=Byte,Rank=1, RemoteObject=True}
Main - 7070: Cannot cast type: {Type=Byte,Rank=0, RemoteObject=True} to: {Type=Byte,Rank=1, RemoteObject=True}
Main - 7072: Undeclared variable 'helpbyte'. (warning #8)
Erel
The strange line comes from me trying to implement " ReadBytes (Dir As String, FileName As String) As Byte() " from B4A Files(Core), post#2.
I have seen the code you posted and I have no idea what it means or how it relates. The best I can guess is that it writes a string to a file and read bytes from the file. As I start with a file previously written file I assumed I only needed this line:
B4X:
b = File.ReadBytes("file that we previously wrote")