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 CodeThe code is 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 ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.