java编码转化

    @Test
    public void testEncode() throws Exception {

        //GBK编码格式源码路径
        String srcDirPath = "d:/zt";
        //转为UTF-8编码格式源码路径
        String utf8DirPath = "d:/zt1";

        //获取所有java文件
        Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(srcDirPath), new String[]{"sql"}, true);
        for (File javaGbkFile : javaGbkFileCol) {
            //UTF8格式文件路径
            String utf8FilePath = utf8DirPath + javaGbkFile.getAbsolutePath().substring(srcDirPath.length());
            //使用GBK读取数据,然后用UTF-8写入数据
            FileUtils.writeLines(new File(utf8FilePath), "GBK", FileUtils.readLines(javaGbkFile, "UTF-8"));
        }

    }
    

你可能感兴趣的:(java)