Answer the question
In order to leave comments, you need to log in
What's going on with C# file encoding?
using System;
using System.IO;
namespace ConsoleApplicationF
{
class Program
{
static void Main(string[] args)
{
string F1 = @"C:\F\f1.txt";
string F2 = @"C:\F\f2.txt";
string CopyF2= "", CopyF1="";
StreamReader FF1 = new StreamReader(F1, System.Text.Encoding.Default);
CopyF1= FF1.ReadToEnd();
FF1.Close();
StreamReader FF2 = new StreamReader(F2, System.Text.Encoding.Default);
CopyF2=FF2.ReadToEnd();
FF2.Close();
StreamWriter FF11 = new StreamWriter(F1);
FF11.Write(CopyF2);
FF11.Close();
StreamWriter FF22 = new StreamWriter(F2);
FF22.Write(CopyF1);
FF22.Close();
}
}
}
using System;
using System.IO;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
string F1 = @"C:\F\f1.txt";
string F2 = @"C:\F\f2.txt";
string F3 = @"C:\F\dewfdewdfhtfhgfchjgfvjhygjudfew.txt";
File.Replace(F1, F2, F3);
File.Move(F3, F1);
}
}
}
Answer the question
In order to leave comments, you need to log in
Judging by the screenshot, you have lost the BOM for UTF-8.
Most likely this happened because you considered the file to be the wrong encoding (in the file you seem to have UTF-8). Use an explicit encoding, such as UTF8Encoding instead of the default one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question