At the beginning, get the Chinese file in the characters are garbled, bird sign look dizzy. So on the StreamReader read the encoding format, the default encoding is ASCII, Single-byte, try to utf8, garbled; try Gb2312,ok!
But another problem appears again, get two files of the number of rows less than 1500 lines, try n times or not, very depressed. Google the next, see try Catch, just think of the release buffer, the result is very happy!
Copy Code code as follows:
private static void Fnfileprocess ()
{
StreamReader reader = new StreamReader (@ "D:\1500.txt", Encoding.GetEncoding ("GB2312"));
StreamWriter writeren = new StreamWriter (@ "D:\English.txt", false, Encoding.UTF8, 1024);
StreamWriter writerch = new StreamWriter (@ "D:\Chinese.txt", false, Encoding.UTF8, 1024);
Try
{
int i = 1;
for (String line = reader. ReadLine (); Line!= null; line = reader. ReadLine ())
{
if (i% 2 = 1)
{
Writeren.writeline (line);
}
Else
{
Writerch.writeline (line);
}
i++;
}
Console.WriteLine (i + "\tok");
}
catch (Exception ex)
{
Console.WriteLine (ex. ToString ());
}
Finally
{
Without emptying the buffer, the resulting file is always less than dozens of lines
Writeren.flush ();
Writerch.flush ();
}
}