using
System;
using
System.IO;
using
System.Text;
using
System.Collections.Generic;
class
FR
{
static
void
Main(){
string
path =
@"D:\GIN\c#\Exercise\笔记2.txt"
;
string
path2 =
@"D:\GIN\c#\Exercise\测试.txt"
;
if
(File.Exists(path)){
Console.WriteLine(
"文件已经存在:"
+ path);
StreamWriter test =
new
StreamWriter(path2,
false
, Encoding.GetEncoding(
"GB2312"
));
foreach
(
string
line
in
File.ReadLines(path)){
test.WriteLine(UTF8ConvertGB2312(line,
"utf-8"
,
"GB2312"
));
}
}
Console.WriteLine(
"Done"
);
Console.ReadLine();
}
static
string
UTF8ConvertGB2312(
string
str,
string
srcCoding,
string
desCoding){
byte
[] barr = Encoding.GetEncoding(srcCoding).GetBytes(str);
barr = Encoding.Convert(Encoding.GetEncoding(srcCoding), Encoding.GetEncoding(desCoding), barr);
return
Encoding.GetEncoding(desCoding).GetString(barr);
}
static
string
GB2312ConvertUTF8(
string
str){
byte
[] barr = Encoding.GetEncoding(
"GB2312"
).GetBytes(str);
barr = Encoding.Convert(Encoding.GetEncoding(
"GB2312"
), Encoding.GetEncoding(
"utf-8"
), barr);
return
Encoding.GetEncoding(
"utf-8"
).GetString(barr);
}
}