JAVA 프로젝트 가 GBK 에서 UTF - 8 로 전환 되 었 습 니 다.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

/**
 *  gbk         utf-8     
 *
 *           .java                                  
 *
 * @author ylg
 */
public class Files {

    /**
     *
     * @param args
     * @throws UnsupportedEncodingException
     * @throws IOException
     */
    public static void main(String[] args) throws UnsupportedEncodingException, IOException {
        Scanner scan = new Scanner(System.in);
        System.out.println("                ");
        String str = scan.nextLine();
        File file = new File(str);
        System.out.println("       ");
        String bm1 = scan.nextLine();
        System.out.println("          ");
        String bm2 = scan.nextLine();
        getAllFiles(file, bm1, bm2);
    }

    /**
     *
     * @param file       
     * @param bm1        
     * @param bm2           
     * @throws FileNotFoundException      
     * @throws UnsupportedEncodingException     
     * @throws IOException io  
     */
    public static void getAllFiles(File file, String bm1, String bm2) throws FileNotFoundException, UnsupportedEncodingException, IOException {
        if (file.isDirectory()) {
            File[] test = file.listFiles();
            for (File test1 : test) {
                //    
                String str = test1.getPath();
                if (str.endsWith("java") & test1.isFile()) {
                    String[] s = str.split("\\.");
                    String filecope = s[0] + "cope." + s[1];
                    System.out.println(filecope);
                    File fil = new File(filecope);
                    //   
                    InputStreamReader isr = new InputStreamReader(new FileInputStream(test1), bm1);
                    OutputStreamWriter osr = new OutputStreamWriter(new FileOutputStream(fil), bm2);
                    int re = -1;
                    while ((re = isr.read()) != -1) {
                        osr.write(re);
                    }
                    isr.close();
                    osr.close();
                    InputStreamReader isrr = new InputStreamReader(new FileInputStream(fil), bm2);
                    OutputStreamWriter osrw = new OutputStreamWriter(new FileOutputStream(test1), bm2);
                    int r = -1;
                    while ((r = isrr.read()) != -1) {
                        osrw.write(r);
                    }
                    isrr.close();
                    osrw.close();
                    boolean d = fil.delete();
                    System.out.println(str + "    utf-8  :" + d);
                }
                getAllFiles(test1, bm1, bm2);
            }
        }
    }

}

결과: TestNG] 실행: C:\\Users\lw\AppData\\Local\Temp\\testng - eclipse - 1374011930\\testng - customsuite. xml
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\BatchCaseExecute. java 파일 변환 utf - 8 성공: t\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\src\\main\\java\luckyclient\\caserun\\exappium\\androidex\\androidBatchExecutecope. jav\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\C\\main\\java\luckyclient\\caserun\\exappium\\androidex\\AndroidCaseExecution. jav파일 변환 utf - 8 성공: true E:\sysun\\svnqit\\AutoClient\\src\\main\\java\luckyclient\\caserun\\exappium\androidex\\AndroidCase LocalDebugcope. javaE:\sysun\\\svnqit\\AutoClient\src\\main\java\luckyclient\\\caserun\\exappium\androidex\AndroidCase LocalDeb
https://www.cnblogs.com/yangliguo/p/7399025.html

좋은 웹페이지 즐겨찾기