【分享】Android Studio專用檔案轉換工具:把ANSI檔案批量另存新檔無BOM的UTF-8檔案

來源:互聯網
上載者:User

標籤:

【分享】Android Studio專用檔案轉換工具:把ANSI檔案批量另存新檔無BOM的UTF-8檔案


在Andoird Studio下編譯java檔案時,經常會出現像下面的錯誤:

Error:(29, 43) 閿欒: 緙栫爜UTF-8鐨勪笉鍙槧灝勫瓧絎?



在這裡,分享一個工具:ANSI檔案批量另存新檔無BOM的UTF-8檔案:

把下面代碼用記事本存為AndroidStudioJava編碼.vbs,雙擊即可使用:

on error resume next Set WshShell=WScript.CreateObject("Shell.Application") dirPath=WshShell.BrowseForFolder(0, "請選擇路徑", 0, "").items().item().path if right(dirPath,1)<>"\" then dirPath=dirpath&"\" ma=inputbox("請輸入要轉換為的編碼","","UTF-8") if ma="" or dirPath="\" or msgbox("在使用前請確認已備份檔案夾"&dirPath,1)=2 then WScript.Quit ‘遍曆檔案夾下的檔案 Set FSO = CreateObject("scripting.filesystemobject") Set f = FSO.GetFolder(dirPath) Set fs = f.files For Each fileN in fs FN=dirPath&fileN.name&"" if ".java"=lcase(right(FN,5)) then Call WriteToFile2(FN, ReadFile(FN, "ANSI_X3.4-1986"), ma) Next Set FSO = Nothing wscript.echo "全部成功" ‘檢測檔案的編碼 Function CheckCode (FileUrl) Dim slz set slz = CreateObject("Adodb.Stream") slz.Type = 1 slz.Mode = 3 slz.Open slz.Position = 0 slz.Loadfromfile FileUrl Bin=slz.read(2) if AscB(MidB(Bin,1,1))=&HEF and AscB(MidB(Bin,2,1))=&HBB Then Codes="UTF-8" elseif AscB(MidB(Bin,1,1))=&HFF and AscB(MidB(Bin,2,1))=&HFE Then Codes="Unicode" else Codes="ANSI" end if slz.Close set slz = Nothing ‘wscript.echo CodesCheckCode=Codes End Function ‘以指定的編碼讀取檔案 Function ReadFile(FileUrl, CharSet) On Error Resume Next Dim Str Set stm = CreateObject("Adodb.Stream") stm.Type = 2 stm.mode = 3 stm.charset = CharSet stm.Open stm.loadfromfile FileUrl Str = stm.readtext stm.Close Set stm = Nothing ‘wscript.echo Str ReadFile = Str End Function ‘以指定的編碼寫檔案 Function WriteToFile (FileUrl, Str, CharSet) On Error Resume Next Set stm = CreateObject("Adodb.Stream") stm.Type = 2 stm.mode = 3 stm.charset = CharSet stm.Open stm.WriteText Strstm.SaveToFile FileUrl, 2 stm.flush stm.Close Set stm = Nothing End FunctionFunction WriteToFile2 (FileUrl, Str, CharSet) On Error Resume Next Set stm = CreateObject("Adodb.Stream") stm.Type = 2 stm.mode = 3 stm.charset = CharSet stm.Open stm.WriteText Strstm.Position = 3Set newStream = CreateObject("Adodb.Stream") newStream.mode = 3newStream.Type = 1newStream.Open()stm.CopyTo(newStream)newStream.SaveToFile FileUrl,2stm.flush stm.Close Set stm = Nothing newStream.flush newStream.Close Set newStream = Nothing End Function



【分享】Android Studio專用檔案轉換工具:把ANSI檔案批量另存新檔無BOM的UTF-8檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.