iOS Question Write and read a text

toro1950

Active Member
Licensed User
Hi, with B4A with the following code I can write and read a configuration for my App

B4X:
Sub saveconfig
    Dim TextWriter As TextWriter
    TextWriter.Initialize(File.OpenOutput(File.DirInternal, "MyConfig", False))
    TextWriter.WriteLine(Text1.text)
    TextWriter.WriteLine(Text2.text)
    TextWriter.WriteLine(Text3.text)
    TextWriter.WriteLine(Text4.text)
    TextWriter.close
End Sub
    
Sub openconfig
    Dim TextReader1 As TextReader
    If File.Exists(File.DirInternal,"MyConfig") Then
    TextReader1.Initialize(File.OpenInput(File.DirInternal,"MyConfig"))
    Text1.text= TextReader1.Readline
    Text2.text= TextReader1.Readline
    Text3.text= TextReader1.Readline
    Text4.text= TextReader1.Readline
    TextReader1.Close
 End Sub
How to do it with B4I for IOS, I searched in the forum but I couldn't
to understand how to do it, can someone help me with an example similar to mine
 

aminoacid

Active Member
Licensed User
Longtime User
Use the File.WriteString and File.ReadString instead of TextWriter/TextReader:


B4X:
Private xui As XUI

.
.
.

File.WriteString(xui.DefaultFolder,"MyConfig",str1)

.
.
.

str1=File.ReadString(xui.DefaultFolder,"MyConfig")
 
Upvote 0

toro1950

Active Member
Licensed User
Thank you Aminoacid, but I don't know if I understood correctly,
should I do this?, always repeat the path. How to close everything
I tried writing and saving everything seems ok, but when reading crashes
B4X:
Sub saveconfig
    File.WriteString(xui.DefaultFolder, "MyConfig",Text1.text)
    File.WriteString(xui.DefaultFolder, "MyConfig",Text2.text)
    .
    .
End Sub

Sub openconfig
    If File.Exists(xui.DefaultFolder, "MyConfig") Then

    Text1.Text =File.ReadString(xui.DefaultFolder,"MyConfig")
    Text2.Text =File.ReadString(xui.DefaultFolder,"MyConfig")
    .
    .
End Sub
 
Upvote 0
Top