I am doing something rather simple in c#, writing a list of strings to text file. My write sub is:
public static bool TextToFile(string fileName, List<string> inString) {
if (!Directory.Exists(Path.GetDirectoryName(fileName)))
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
try {
if (File.Exists(fileName))
File.Delete(fileName);
const int BufferSize = 65536; // 64 Kilobytes
using (StreamWriter sw = new StreamWriter(fileName, true, Encoding.UTF8, BufferSize)) {
if (inString.Count > 0) {
foreach (string str in inString) {
sw.WriteLine(str);
}
}
else
sw.WriteLine("");
}
return true;
}
catch {
return false;
}
}
I am getting extra stuff at the beginning of the first line though.
It does not show in a regular text editor, but when I opened in ultraedit, and went to hex mode, I saw this:
My programs that read the text file do see the characters, and confuse it. My list of strings is super clean. I am sometimes writing 100 mb text files, so am setting the buffer to 64k, but I tried leaving it as default with same results. I am on win7 64 bit, using VS 2013.