当前位置 : 主页 > 网络编程 > 其它编程 >

将汉字转成拼音

来源:互联网 收集:自由互联 发布时间:2023-07-02
转成拼音工具类packageutils;importnet.sourceforge.pinyin4j.PinyinHelper;publicclassPinyinU 转成拼音工具类 package utils;import net.sourceforge.pinyin4j.PinyinHelper;public class PinyinUtils {/*** 提取每个汉字的首字母*
转成拼音工具类packageutils;importnet.sourceforge.pinyin4j.PinyinHelper;publicclassPinyinU

转成拼音工具类

package utils;import net.sourceforge.pinyin4j.PinyinHelper;public class PinyinUtils {/*** 提取每个汉字的首字母* * param str* return String*/public static String getPinYinHeadChar(String str) {String convert "";for (int j 0; j 测试类

package szoa;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;public class testPinyin {public static void main(String[] args) throws IOException {String filename "C:\\Users\\sjx\\Desktop\\a.txt";BufferedReader br new BufferedReader(new InputStreamReader(new FileInputStream(filename), "utf-8")); //这里可以控制编码String line null;BufferedWriter out new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\Users\\sjx\\Desktop\\b.txt",true)));while ((line br.readLine()) ! null) {line PinyinUtils.getPinYin(line);out.write(line "\r\n");}out.close();}}

 

转:https://www.cnblogs.com/sjxbg/p/10440151.html

网友评论