依赖引入,pom.xml

<dependency><groupId>com.github.stuxuhai</groupId><artifactId>jpinyin</artifactId><version>1.1.8</version></dependency>

封装工具类 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;/*** Created by zhangzhenhua*/
public class SimpleToTraditionalUtils {public static void main(String[] args) {SimpleChineseToTraditionalWithPath("F:\\testFile\\test");}public static void SimpleChineseToTraditionalWithPath(String path){ArrayList<String> tempArray = new ArrayList<>();ArrayList<String> fileList = traverseFolder2(path , tempArray);if(CollectionUtils.isEmpty(fileList)){return;}for (int i = 0; i<fileList.size() ; i++){readFileAndReWriteInNewFile(fileList.get(i));}System.out.println("转换结束");}public static void readFileAndReWriteInNewFile(String filePath){// 简体转繁体try{BufferedReader bufRead = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath))));StringBuilder strBuffer = new StringBuilder();Pattern pattern = Pattern.compile("[\u4e00-\u9fcc]+");for (String temp; (temp = bufRead.readLine())!= null; ){if (pattern.matcher(temp).find()){temp = convertToTraditionalChinese(temp);}strBuffer.append(temp);strBuffer.append(System.getProperty("line.separator"));}//本地调试打印System.out.println(strBuffer.toString());bufRead.close();PrintWriter printWriter = new PrintWriter(filePath);printWriter.write(strBuffer.toString().toCharArray());printWriter.flush();printWriter.close();}catch (IOException e){e.printStackTrace();}}/*** 遍历传入的根文件夹,获取每一级文件夹的每个文件* @param path 文件夹路径* @param listFileName 返回文件路径的list* @return*/public static ArrayList<String> traverseFolder2(String path , ArrayList<String> 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;}/*** 简体转换为繁体* @param simpleStr 要转换的字符串* @return*/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转换基本没发现问题,自己仔细验证了项目转换为繁体后的页面显示和功能都正常,除了唯一看到“系”字转换错误。

Java项目前后端文件简体转换繁体相关推荐

  1. 简体转换繁体的郁闷话题,问题终于解决了

     1 比例:  2  如繁体:發財頭髮  3 如果在C#程序中的head部分直接 < meta  http-equiv ="Content-Type"  content =& ...

  2. 更改vscode Java项目的.class文件输出路径

    1.在vscode里面按下快捷键ctrl+shift+p 2.输入Classpath 3.点击Output下的Browse选择.class文件的输出路径 4.如图,选择完以后,.class文件的输出层 ...

  3. Java 通过csv表格文件生成转换SQL文件

    public static void main(String[] args) throws IOException {ArrayList<String[]> csvList = new A ...

  4. PHP类UTF8编码内的繁简转换-繁体-简体

    js网页繁体简体转换 均只支持 UTF8 文本,所以如果获得的来源是 $_GET 的话, 就有必要转换一下编码了.用到的函数是: $str = $_GET['str']; // 简体到utf8 $st ...

  5. java utf8 简繁转换 类库_在Java中进行中文繁体简体转换,基于OpenCC(Open Chinese Convert)方案...

    一.OpenCC介绍 OpenCC (Open Chinese Convert,开放中文转换) 是一个用于中文简繁转换的开源项目,支持词汇级别的转换.异体字转换和地区习惯用词转换(中国大陆.台湾.香港 ...

  6. java 中文简体与繁体的转换

    虽然说中文繁体与简体的转换在项目中使用到的概念很小,但是这也算是一个有工具类了,为了以后可能的需要,在这里说一下: import com.spreada.utils.chinese.ZHConvert ...

  7. java springboot VUE 在线学习平台系统开发mysql数据库web结构java编程计算机网页源码maven项目前后端分离

    一.源码特点   springboot VUE 在线学习平台系统是一套完善的完整信息管理类型系统 前后端分离,结合springboot框架和VUE完成本系统,对理解JSP java编程开发语言有帮助系 ...

  8. python tkinter 中文文档_Python实现中文文档的简体与繁体互相转换

    封面图片:<Python程序设计实验指导书>,董付国编著,清华大学出版社,2019.4 ============= 本文重点是一个第三方工具的使用,首先从下面的地址下载这两个文件并存放于程 ...

  9. Python实现中文文档的简体与繁体互相转换

    本文重点是一个第三方工具的使用,首先从下面的地址下载这两个文件并存放于程序文件所在文件夹. https://raw.githubusercontent.com/skydark/nstools/mast ...

  10. UTF-8的繁体与简体转换

    转自:http://www.cnblogs.com/microtea/archive/2006/05/28/411394.html 本人注:曾一直想把编码问题搞清楚,到现在也没有具体研究.若读者有兴趣 ...

最新文章

  1. J2ME下漫游(追逐)AI的实现
  2. 实时通信RTC技术栈之:视频编解码
  3. php foreach id是否存在数组_45个PHP程序性能优化的小技巧,赶紧收藏吧
  4. Exception in thread main java.io.IOException: (null) entry in command string: null chmod 0700 E:\t
  5. Spark笔记:RDD基本操作(下)
  6. SQL语句(DQL)
  7. fopen后面参数对文件操作的相应关系
  8. 期末C语言45分能过的吗,C语言—期末小黄衫获奖感言
  9. 从单张图重建三维人体模型综述(二)
  10. CleanMyPC比360管家好用N倍的电脑清理软件
  11. 如何在Java中将Excel(XLSX)转换为Word(DOCX)
  12. 数字签名技术原理介绍
  13. 安装protobuf可能遇到的问题
  14. 使用python内置函数进行常规API接口调用
  15. 产品可用性原则:网页设计点睛秘笈
  16. 批量转账到支付宝ISV(API接口流程步骤)
  17. 2022年康复医学治疗技术高级职称考试题库及答案
  18. 软件测试真假童子,19岁年薪千万,他打王者荣耀打成了“游戏圈的TFBOYS”
  19. Python+pandas把多个DataFrame对象写入Excel文件中同一个工作表
  20. 2020-CIKM-DisenHAN: Disentangled Heterogeneous Graph Attention Network for Recommendation

热门文章

  1. 在Novell NetWare中支持IP
  2. 微信公众号怎么集赞服务器,微信公众号分享集赞吸粉方案,人人可复制
  3. 服务器版系统里无线网卡如何打开,无线网卡被禁用了怎么开启
  4. 向工程腐化开炮:Java代码治理
  5. mtk android mt6573项目 root升级包制作
  6. 20200525-生物技术-四川师范大学自考生物技术(本科)考试计划.txt
  7. RocketMQ(十)RocketMQ事务消息
  8. 计算机制图大赛,制图大赛简介
  9. 如何快速发表一篇SCI论文
  10. cdn回源php_CDN回源、网站解析 是什么意思?