转成拼音工具类
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