[問題] txt檔儲存為ANSI 不知道問題出在哪裡?

看板C_Sharp (C#)作者 (jpyama)時間10年前 (2015/05/21 12:12), 編輯推噓1(103)
留言4則, 3人參與, 最新討論串1/1
只是想寫個簡單的小程式 但卡在txt檔需要存成ANSI檔列印出來才不會變成亂碼 請求大大指點要怎麼修正才能解決錯誤 private void button1_Click(object sender, EventArgs e) { FileStream fileStream = new FileStream(@"C:\Users\user\Desktop\wp520.txt", FileMode.Create); fileStream.Close(); using (StreamWriter sw = new StreamWriter(@"C:\Users\user\Desktop\wp520.txt", System.Text.Encoding.Default)) { 或是我少宣告什麼呢? http:// ppt.cc/OOqXl 縮網址 感激不盡!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.105.30.210 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1432181546.A.4C3.html

05/21 13:21, , 1F
System.Text.Encoding.Default,這邊台灣會是預設utf8
05/21 13:21, 1F

05/21 13:21, , 2F
或是big5,所以要用System.Text.Encoding.ANSI
05/21 13:21, 2F

05/21 13:38, , 3F
為什麼你要先建一個檔案再close...
05/21 13:38, 3F

05/21 16:10, , 4F
已解決~~ 感謝!!
05/21 16:10, 4F
文章代碼(AID): #1LNLigJ3 (C_Sharp)
文章代碼(AID): #1LNLigJ3 (C_Sharp)