L leitor79 Active Member Licensed User Longtime User Jul 9, 2014 #1 Hi, I'm having an issue with a file a write and rewrite over and over (sometimes it arrives with the previous data), and I'm trying to figuring out the case. One thing I have doubt about is regarding the closing. I don't know if I'm using the correct methods and in the correct order to close the file. Out is the OutputStream, tw is the TextWriter: Code: Copy . . . tw.Initialize(Out) tw.WriteLine(S) tw.Flush tw.Close Out.close I had the Out.Flush sentence also, but I've removed it since I was getting an exception. Any ideas? Regards!
Hi, I'm having an issue with a file a write and rewrite over and over (sometimes it arrives with the previous data), and I'm trying to figuring out the case. One thing I have doubt about is regarding the closing. I don't know if I'm using the correct methods and in the correct order to close the file. Out is the OutputStream, tw is the TextWriter: Code: Copy . . . tw.Initialize(Out) tw.WriteLine(S) tw.Flush tw.Close Out.close I had the Out.Flush sentence also, but I've removed it since I was getting an exception. Any ideas? Regards!
Erel B4X founder Staff member Licensed User Longtime User Jul 9, 2014 #2 Are you trying to append a line of text to an existing file? Upvote 0
L leitor79 Active Member Licensed User Longtime User Jul 9, 2014 #3 Hi Erel, thanks for your answer! Actually the file can exist or not, it depends on another process. This is how I'm opening it: Code: Copy Out = File.OpenOutput(File.DirRootExternal, "sr", True) tw.Initialize(Out) tw.WriteLine(S) The reason for asking is because I'm not familiar with the Java flush... I know what it is but I don't know when should I use it.. thank you very much! Upvote 0
Hi Erel, thanks for your answer! Actually the file can exist or not, it depends on another process. This is how I'm opening it: Code: Copy Out = File.OpenOutput(File.DirRootExternal, "sr", True) tw.Initialize(Out) tw.WriteLine(S) The reason for asking is because I'm not familiar with the Java flush... I know what it is but I don't know when should I use it.. thank you very much!
Erel B4X founder Staff member Licensed User Longtime User Jul 9, 2014 #4 You don't need to call flush as the cached data is written anyway when TextWriter is closed. The correct code is: Code: Copy Out = File.OpenOutput(File.DirRootExternal, "sr", True) tw.Initialize(Out) tw.WriteLine(S) tw.Close 'no need to close Out as it will be closed when you call tw.close Upvote 0
You don't need to call flush as the cached data is written anyway when TextWriter is closed. The correct code is: Code: Copy Out = File.OpenOutput(File.DirRootExternal, "sr", True) tw.Initialize(Out) tw.WriteLine(S) tw.Close 'no need to close Out as it will be closed when you call tw.close
L leitor79 Active Member Licensed User Longtime User Jul 9, 2014 #5 Thank you very much, Erel! Upvote 0
J Jody New Member Licensed User Longtime User Aug 6, 2014 #6 Hi Erel How Do i disable the Textwriter1.flush from sending a newline <LF> character When i Flush? This is an embedded project and i really need to Disable this Thank you kindly Best Regards jody Upvote 0
Hi Erel How Do i disable the Textwriter1.flush from sending a newline <LF> character When i Flush? This is an embedded project and i really need to Disable this Thank you kindly Best Regards jody
Erel B4X founder Staff member Licensed User Longtime User Aug 6, 2014 #7 Call TextWriter.Write instead of TextWriter.WriteLine. Upvote 0