雖然目前不知道這個要用在哪裡啦...

不過我想也許還是用的著....

就給它記下來囉

byte[] big5Bytes = null;

string FilePath = Server.MapPath("~/txt/test.txt");

using (System.IO.FileStream fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Open))
 {
    //讀big5編碼bytes
    big5Bytes = new byte[fs.Length];
    fs.Read(big5Bytes, 0, (int)fs.Length);
 }

//將big5轉成utf8編碼的bytes
byte[] utf8Bytes = System.Text.Encoding.Convert(System.Text.Encoding.GetEncoding("BIG5"), System.Text.Encoding.UTF8, big5Bytes);

//將utf8 bytes轉成utf8字串
System.Text.UTF8Encoding encUtf8 = new System.Text.UTF8Encoding();

string utf8Str = encUtf8.GetString(utf8Bytes);

Response.Write(utf8Str);
arrow
arrow
    全站熱搜

    鴨爸 發表在 痞客邦 留言(0) 人氣()