是否是中文
public boolean checkChinese(String chinese)
{
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(chinese);
if (m.find()) {
return true;
}
return false;
}
从文档中提取中文语句
48 return new ResultModel("修改成功");
59 return new ResultModel("添加成功");
106 return new ResultModel("修改成功");
180 return "数据为空";
187 return "添加成功";
@Test
public void getChineseforomFile(){
List<String> stringsList = new ArrayList<>();
FileReader fileReader = new FileReader("C:\\Users\\Administrator\\Desktop\\项目后台的中文提醒内容.txt");
List<String> result = fileReader.readLines();
for (String str : result) {
String[] split = StrUtil.subBetweenAll(str, "\"", "\"");
for (String s : split) {
if(checkChinese(s)){
stringsList.add(s);
}
}
}
stringsList = stringsList.stream().distinct().collect(Collectors.toList());
stringsList.forEach(System.out::println);
}