"Share" Android Studio dedicated file Conversion tool: Save ANSI files in bulk as UTF-8 files without BOM

Source: Internet
Author: User
Tags readfile

"Share" Android Studio dedicated file Conversion tool: Save ANSI files in bulk as UTF-8 files without BOM


When compiling Java files under Andoird Studio, there are often errors like the following:

Error: (29, 43) downloading message: Ke policy home UTF-8 fermium Âμà switches Å è¡#̈亞 槧 hao 勫 瓧 quilting?



Here, share a tool: ANSI files are saved in bulk as UTF-8 files without a BOM:

Save the following code in Notepad as Androidstudiojava encoded. vbs, double-click to use:

On Error Resume Next Set wshshell=wscript.createobject ("Shell.Application") dirpath=wshshell.browseforfolder (0, " Select Path ", 0," "). Items (). Item (). path if Right (dirpath,1) <>" \ "then dirpath=dirpath&" \ "Ma=inputbox (" Please enter the encoding to be converted to "," "," UTF-8 ") if Ma=" "or dirpath=" \ "or MsgBox (" Confirm the backed up folder before use "&dirpath,1) =2 then Wscript.Quit ' traverse the file under the folder 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)) th En call WriteToFile2 (FN, ReadFile (FN, "ansi_x3.4-1986"), MA) Next Set FSO = Nothing WScript.Echo "All succeeded" the encoding Function of the detection file 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 ' reads a file with the specified encoding 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 ' writes a file with the specified encoding function writetofile (FILEURL, str, CharS ET) 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 = createobj ECT ("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.O Pen () STM. CopyTo (newstream) newstream.savetofile Fileurl,2stm.flush stm.Close Set stm = Nothing Newstream.flush newstream.close Set newstream = Nothing End Function 



"Share" Android Studio dedicated file Conversion tool: Save ANSI files in bulk as UTF-8 files without BOM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.