text writer/reader error exception

locxtronic

Member
Licensed User
Longtime User
guys, i try to catch an error if the file is not directory by using try..catch.. here is my code.. but code in catch is not working.. it suppose to create new file if file is not in directory

B4X:
Sub ReadTextReader
    Dim TextReader1 As TextReader
   
   Try
      
       TextReader1.Initialize(File.OpenInput(File.DirInternal, "connection_setting.txt"))
       ip_number_input.Text = TextReader1.ReadLine
      port_number_input.Text = TextReader1.ReadLine    
       TextReader1.Close
   Catch
      Dim TextWriter1 As TextWriter
       TextWriter1.Initialize(File.OpenOutput(File.DirInternal, "connection_setting.txt", False))
       TextWriter1.WriteLine("192.168.1.1")
      TextWriter1.WriteLine("2000")
       TextWriter1.Close
      Msgbox("Save file created","Create Save File")
   End Try
End Sub
 
Last edited:
Top