I am trying to create a logging file(my app is crashing on 1 customers sight), and I
get the error message "java.io.FileNotFoundException: true/newfile.log (No such file or directory)"
when I try to open/write to the file.
Here is my code.
B4X:
Sub LogWrite(EventsLog As String)
If File.ExternalWritable = False Then
Msgbox("Cannot write log file.", "")
Return
Else
Dim TextWriter1 As TextWriter
TextWriter1.Initialize(File.OpenOutput(File.ExternalWritable, "newfile.log", True))
TextWriter1.WriteLine("- " & EventsLog)
TextWriter1.Close
End If
End Sub
Hi @rkmoray: Mr. Erel frowns at using TexWriter and TextReader. You should have a code similar to this:
B4X:
Sub LogWrite(EventsLog As String)
Dim rp As RuntimePermissions 'need runtime permissions lib. This line preferably in Starter service
If File.ExternalWritable = False Then
MsgboxAsync("Cannot write log file.", "")
Return
Else
File.WriteString(rp.GetSafeDirDefaultExternal(""), "newfile.log", EventsLog)
End If
End Sub