aegidius20
Member
I'm writing a file using TextWriter from my app in DirInternal, then saving it via SaveAs (published code snippet). About half the time it works perfectly, but sometimes the resulting file is zero bytes long.
Is there any flushing I need to do?
How can I see the file in DirInternal? Files (Google app) won't show it.
Then closing the TextWriter and copying it using SaveAs:
Is there any flushing I need to do?
How can I see the file in DirInternal? Files (Google app) won't show it.
B4X:
Private Logger As TextWriter
Logger.Initialize(File.OpenOutput(File.DirInternal, "tempfile.csv", False))
Logger.WriteLine(stuff)
Then closing the TextWriter and copying it using SaveAs:
B4X:
Logger.Close
' SaveAs the file to someplace sensible (like Downloads)
' Date/time code to generate a unique filename to save
Dim filename As String
DateTime.DateFormat = "yyyyMMdd"
DateTime.TimeFormat = "HHmmss"
filename = "Output-" & DateTime.Date(DateTime.Now) & "-" & DateTime.Time(DateTime.Now) & ".csv"
Wait For (SaveAs(File.OpenInput(File.DirInternal, "tempfile.csv"), "application/octet-stream", filename)) Complete (Success As Boolean)
File.Delete(File.DirInternal, "tempfile.csv")