<dependency>
<groupId>com.github.stuxuhai</groupId>
<artifactId>jpinyin</artifactId>
<version>1.1.8</version>
</dependency>
public static void main(String[] args) throws Exception {
List<String> strings = readFile();
System.out.println(strings);
List<String> strings1 = cvtList(strings);
writeFile(strings1);
}
public static List<String> readFile() throws Exception {
FileInputStream fis=new FileInputStream("aa.txt");
InputStreamReader isr=new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
List<String> list=new ArrayList<>();
String line="";
while ((line=br.readLine())!=null) {
list.add(line);
}
br.close();
isr.close();
fis.close();
return list;
}
public static void writeFile( List<String> list) throws Exception {
FileOutputStream fos=new FileOutputStream(new File("aa2.txt"));
OutputStreamWriter osw=new OutputStreamWriter(fos, "UTF-8");
BufferedWriter bw=new BufferedWriter(osw);
for(String arr:list){
bw.write(arr+"\t\n");
}
bw.close();
osw.close();
fos.close();
}
public static List<String> cvtList(List<String> list) {
List<String> rst=new ArrayList<>();
for (String str : list) {
String s = convertToSimplifiedChinese(str);
rst.add(s);
}
return rst;
}
public static String convertToSimplifiedChinese(String pinYinSt) {
String tempStr = null;
try {
tempStr = ChineseHelper.convertToSimplifiedChinese(pinYinSt);
} catch (Exception e) {
tempStr = pinYinSt;
e.printStackTrace();
}
return tempStr;
}