- Home /
Unity does not finish write file (filecontent suddenly ends)
Basically i've got this code:
LateUpdate(){
.... some code ....
using (var stream = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write))
{
var writer = new StreamWriter(stream, Encoding.UTF8);
writer.Write(builder.ToString());
}
....
}
and the file end suddenly like this:
... 68 148 previous lines ...
0.59442 0.10000 0.50537 000
0.59659 0.10000 0.50844 000
0.59875 0.10000 0.51152 000
0.60092 0.10000 0.51459 000
0.6030 <<< --- this should look like the previous lines --->>>
Answer by Bunny83 · May 23, 2017 at 11:37 PM
The StreamWriter class also does chunked writing. You should either call Flush when you're done writing to ensure the internal buffers are flushed into the file, ot (which would be the more natural solution) wrap the StreamWriter instance in another using statement:
using (var stream = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write))
using (var writer = new StreamWriter(stream, Encoding.UTF8))
{
writer.Write(builder.ToString());
}
Your answer
Follow this Question
Related Questions
Importing files from a path via C# script 0 Answers
File saving error 1 Answer
Simple way to get the most recently updated file and output to screen? C# Unity 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers