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 detectEncodingF romByteOrderMar ks. 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.GetDirecto ryName(Applicat ion.ExecutableP ath) +
@"\intext.tx t";
string OutputPath = Path.GetDirecto ryName(Applicat ion.ExecutableP ath)
+ @"\outtext.txt" ;
string In;
string Out;
using (StreamReader Input = new StreamReader(In putPath))
// using (StreamReader Input = new StreamReader(In putPath, true)) <<
construct
{
using (StreamWriter Output = new StreamWriter(Ou tputPath))
{
while ((In = Input.ReadLine( )) != null)
{
Out = DoSomethingTo(I n);
Output.WriteLin e(Out);
}
}
}
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 detectEncodingF romByteOrderMar ks. 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.GetDirecto ryName(Applicat ion.ExecutableP ath) +
@"\intext.tx t";
string OutputPath = Path.GetDirecto ryName(Applicat ion.ExecutableP ath)
+ @"\outtext.txt" ;
string In;
string Out;
using (StreamReader Input = new StreamReader(In putPath))
// using (StreamReader Input = new StreamReader(In putPath, true)) <<
construct
{
using (StreamWriter Output = new StreamWriter(Ou tputPath))
{
while ((In = Input.ReadLine( )) != null)
{
Out = DoSomethingTo(I n);
Output.WriteLin e(Out);
}
}
}
Comment