栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Java项目前后端文件简体转换繁体

Java项目前后端文件简体转换繁体

依赖引入,pom.xml


            com.github.stuxuhai
            jpinyin
            1.1.8
        

封装工具类 SimpleToTraditionalUtils

package com.iot.power.boot.utils;


import com.github.stuxuhai.jpinyin.ChineseHelper;
import org.apache.commons.collections.CollectionUtils;

import java.io.*;
import java.util.ArrayList;
import java.util.regex.Pattern;


public class SimpleToTraditionalUtils {

    public static void main(String[] args) {
        SimpleChineseToTraditionalWithPath("F:\testFile\test");
    }

    public static void SimpleChineseToTraditionalWithPath(String path){
        ArrayList tempArray = new ArrayList<>();
        ArrayList fileList = traverseFolder2(path , tempArray);
        if(CollectionUtils.isEmpty(fileList)){
            return;
        }
        for (int i = 0; i traverseFolder2(String path , ArrayList listFileName) {
        File file = new File(path);
        if (file.exists()) {
            File[] files = file.listFiles();
            if (files == null || files.length == 0) {
                System.out.println("文件夹是空的!");
                return null;
            } else {
                for (File file2 : files) {
                    if (file2.isDirectory()) {
                        traverseFolder2(file2.getAbsolutePath(),listFileName);
                    } else {
                        String solutePath = file2.getAbsolutePath();
                        //以下文件格式根据自己实际添加或删除
                        if (solutePath.endsWith(".jsp") || solutePath.endsWith(".js")
                                || solutePath.endsWith(".html") || solutePath.endsWith(".java")
                                || solutePath.endsWith(".properties") || solutePath.endsWith(".sql")
                         ){
                            listFileName.add(file2.getAbsolutePath());
                        }
                    }
                }
            }
        } else {
            System.out.println("文件不存在!");
        }
        return listFileName;
    }

    
    public static String convertToTraditionalChinese(String simpleStr) {
        String tempStr;
        try {
            tempStr = ChineseHelper.convertToTraditionalChinese(simpleStr);
        } catch (Exception e) {
            tempStr = simpleStr;
            e.printStackTrace();
        }
        //本地验证系字转换有问题,单独处理
        return tempStr.replace("係", "系");

    }

}


写在结尾
本人实际项目中对.html、.js、.java、.sql、.properties转换基本没发现问题,凭自己肉眼验证了项目转换为繁体后的页面显示和功能都正常,除了唯一看到“系”字转换错误。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/735946.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号