复制代码 代码如下:
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
{
//不清空缓冲区,得到的文件总是少几十行
writerEn.Flush();
writerCh.Flush();
}
}
新闻热点
疑难解答
图片精选