I've noticed after copying a text file line by line and comparing, that the
original had several bytes of data at the beginning denoting its encoding.
How do I use that in my copy?
My original code shown below, didn't produce a perfect copy, so I used the
StreamReader construct that includes detectEncodingFromByteOrderMarks. But I
need to pass that to the construct for my StreamWriter so I need to be able
to work out the encoding type somehow. How please?
string InputPath = Path.GetDirectoryName(Application.ExecutablePath) +
@"\intext.txt";
string OutputPath = Path.GetDirectoryName(Application.ExecutablePath)
+ @"\outtext.txt";
string In;
string Out;
using (StreamReader Input = new StreamReader(InputPath))
// using (StreamReader Input = new StreamReader(InputPath, true)) <<
construct
{
using (StreamWriter Output = new StreamWriter(OutputPath))
{
while ((In = Input.ReadLine()) != null)
{
Out = DoSomethingTo(In);
Output.WriteLine(Out);
}
}
}