Where is the value of myString.I have issues when executig this:
The output is always only one line at the top, no strings are appendedB4X:Dim myString As String File.OpenOutput(File.DirApp,"test.txt",True) File.WriteString(File.DirApp,"test.txt",myString)
Have you checked what File.WriteString is meant to do?Its filled before with the data...the value is written correct, but no appending.
I also tried other Directories like C:\Test, but also the same result
Is it add the value at all?Its filled before with the data...the value is written correct, but no appending.
I also tried other Directories like C:\Test, but also the same result
Public Sub WriteErrorLog(str As String)
Try
Dim tmpTextWriter As TextWriter
Dim tmpWhereFrom As String
If Main.IsServer = True Then
tmpWhereFrom = "-Server-"
Else
tmpWhereFrom = "-Client-"
End If
DateTime.DateFormat = "dd-MM-yyyy"
Dim LogDate As String = DateTime.Date(DateTime.Now)
DateTime.TimeFormat = "HH:mm:ss.SSS"
If File.Exists(Main.DirApp, "Logs/" & LogDate & "-" & Main.BrandName & tmpWhereFrom & "ErrorLog.txt") = True Then
' If File.Size(Main.DirApp, "Logs/" & LogDate & "-" & Main.BrandName & tmpWhereFrom & "ErrorLog.txt") > 100000000 Then
' File.Delete(Main.DirApp, "Logs/" & LogDate & "-" & Main.BrandName & tmpWhereFrom & "ErrorLog.txt")
' End If
End If
tmpTextWriter.Initialize(File.OpenOutput(Main.DirApp, "Logs/" & LogDate & "-" & Main.BrandName & tmpWhereFrom & "ErrorLog.txt", True))
tmpTextWriter.WriteLine(DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) & " " & str)
tmpTextWriter.Close
DateTime.TimeFormat = "HH:mm:ss"
Catch
ShowLog("Error: Write Error Log", False, False, LastException.Message)
End Try
End Sub
Hope you can use it.Or, use file.reastring, concatenate the new value and then use file.writestring. Of course textwriter is better option...
Andreas.
Sub FileAppendString(FileDir As String, FileName As String, NewString As String)
Dim NewBytes() As Byte = NewString.GetBytes("UTF8")
Dim fh As OutputStream = File.OpenOutput(FileDir, FileName, True)
fh.WriteBytes(NewBytes, 0, NewBytes.Length)
fh.Close
End Sub
Sub FileAppendLine(FileDir As String, FileName As String, NewLine As String)
FileAppendString(FileDir, FileName, NewLine & CRLF)
End Sub
Public Sub Schreibpreis(str As String)
Try
Dim tmpTextWriter As TextWriter
DateTime.DateFormat = "dd.MM.yyyy"
DateTime.TimeFormat = "HH:mm:ss"
If File.Exists(File.DirApp, "test.txt") = True Then
End If
tmpTextWriter.Initialize(File.OpenOutput(File.DirApp, "test.txt", True))
tmpTextWriter.WriteLine(DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) & " " & myString)
tmpTextWriter.Close
Catch
Log("Error: Write Error Log " & LastException.Message)
End Try
End Sub
Sub WriteTextOutput (Dir As String, FileName As String, Contents As String)
Dim Out As OutputStream = File.OpenOutput(Dir, FileName, True)
Dim b() As Byte = (CRLF & Contents).GetBytes("UTF8")
Out.WriteBytes(b, 0, b.Length)
Out.Close
End Sub
DateTime.DateFormat = "dd.MM.yyyy HH:mm:ss"
Dim myString As String = DateTime.Date(DateTime.Now) & " - " & "Some log data"
WriteTextOutput(File.DirApp, "test.txt", myString)