I do not know how to use OutputStream - the code below gives me an error on
Writer.WriteLine(OS.WriteBytes(Data,0,text2.Length-1))
Obviously, I am missing the point.
Any help will be appreciated. Thank you.
Writer.WriteLine(OS.WriteBytes(Data,0,text2.Length-1))
B4X:
'try converting text2 which contains UFT8 characters
Dim Data() As Byte
Data = text2.GetBytes("ISO-8859-1") '("ASCII") - ASCII provides a limited set of 128 characters and not the ANSI equivalent
'1. deletefile in case
If File.Exists (File.DirRootExternal& "/Test/", "t120.txt") Then
File.Delete(File.DirRootExternal& "/Test/", "t120.txt")
End If
'2. write new string file
Dim OS As OutputStream
OS.InitializeToBytesArray(120)
Dim Writer As TextWriter
Writer.Initialize2(File.OpenOutput(File.DirRootExternal& "/Test/", "t120.txt",False),"ISO-8859-1")
Writer.WriteLine(OS.WriteBytes(Data,0,text2.Length-1))
Writer.Close
'3 read file ("ISO-8859-1")
text2=""
Dim Reader As TextReader
Reader.Initialize(File.OpenInput(File.DirRootExternal& "/Test/", "t120.txt"))
text2 = Reader.ReadLine
Reader.Close
Log(text2)
Log("t2 len" & text2.Length)
Obviously, I am missing the point.
Any help will be appreciated. Thank you.