從UTF8轉ANSI發現的問題 u202a

2021-10-10 21:58:58 字數 1174 閱讀 8104

**-讀取乙個utf8編碼的檔案

public static listreadfilecontentline(string filename) throws ioexception 

reader.close();

arraylist var5 = lines;

return var5;

} catch (ioexception var14) finally catch (ioexception var13) }}

}

**-寫入ansi編碼的檔案,編碼使用:gb2312

public static void writewinfile(string outpath, listlines, string charsetname) throws exception 

string source = sb.tostring();

osw.write(source);

osw.flush();

osw.close();

} catch (exception var11) finally

}

轉換前的檔案內容

del /f /s /q d:\檔案\檔案\測試檔案一.txt
轉換後的檔案內容

del /f /s /q ?d:\檔案\檔案\測試檔案一.txt
前面多了乙個問號

這個問題困住我一下午+一晚上,最終破解;

原因如下:

在製作這個檔案的時候,是乙個新來的實習生幫忙製作的,他的操作如下

windows系統,在檔案右鍵屬性->安全->物件名稱,選中檔案路徑,拷貝檔案路徑。

把路徑複製到notepad中你會發現和正常的檔案路徑沒有任何區別;

但是把路徑複製到intelj idea的""字串中間,會發現如下:

在非引號的文字下展示也是正常的,只有在引號中是如圖上所示。

最終找到原因

window下轉義字元:\u202a,用於表示從左到右,而且並不是每次複製都能複製到這個字元的哈,有規律,需要摸索一下;

最後在**中處理一下就好了;

ANSI與UTF 8編碼轉換

將ansi編碼裝換為utf 8在windows mfc環境下測試下面的 static int ansi2utf8 in const char csrc,out char cdest 以下 將utf 8 轉換為gb2312 intutf8togb2312 const char sourcebuf,si...

utf8與ansi之間的轉換

include stdafx.h include include include include include include namespace fs boost filesystem const int count 1024 const std string ret success succe...

java gbk轉utf 8亂碼問題

最近在做乙個反饋功能,把資料反饋到對方公司 我公司是gbk編碼,對方公司是utf 8編碼。因此,我需要將gbk編碼資料轉換成utf 8編碼資料,這樣對方 才不會亂碼。最簡單的方法是將httpclient的contentcharset設定為utf 8 如果contentcharset是gbk並且又不想...