/**
* 读取工程中的text文件
* @param filePath
* @return
*/
public static List<String> readFileByLines(String filePath) {
List<String> li = new ArrayList<String>();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(
filePath), "UTF-8"));
String tempString = null;
while ((tempString = br.readLine()) != null) {
li.add(tempString);
}
br.close();
return li;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
/**
* 电话号码中间加密显示
* @param phone
* @return
*/
public static String encryptionPhoneNum(String phone){
String encryptionphone = phone.replaceAll("(\\d{3})\\d{4}(\\d{2})","$1****$2");
return encryptionphone;
}
/**
* 邮箱前面加密
* @param email
* @return
*/
public static String encryptionEmail(String email){
String encrytionemail = email.replaceAll("(\\w[-\\w.+])*(@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14})", "$1********$2");
return encrytionemail;
}
/**
* 座机显示加密
* @param phoneNum
* @return 400(-\d{3,4}){2}
*/
public static String encryptionFixedLine(String phoneNum){
String encryptionLine="---";
if("1".equals(isFixed400or800(phoneNum))){
encryptionLine = phoneNum.replaceAll("([0][1-9]{0,3})(-)([0-9]{5,10})", "$1$2********");
}else if("2".equals(isFixed400or800(phoneNum))){
encryptionLine = phoneNum.replaceAll("(400)(-\\d{3,4}){2}", "$1-****$2");
}else{
encryptionLine = phoneNum.replaceAll("(800)(-\\d{3,4}){2}", "$1-****$2");
};
return encryptionLine;
}
/**
* 判断400,800,座机
* @param phoneNum
* @return
*/
public static String isFixed400or800(String phoneNum){
String compare ="0";
if(Pattern.matches("[0][1-9]{0,3}-[0-9]{5,10}", phoneNum)){
compare ="1";
}else if(Pattern.matches("400(-\\d{3,4}){2}", phoneNum)){
compare ="2";
}else if(Pattern.matches("800(-\\d{3,4}){2}", phoneNum)){
compare ="3";
}else{
compare ="1";
}
return compare;
}
/**
* 匹配分词中的特殊字符串后加高亮
* @param wordStr
* @param color
* @return
*/
public static String specialCharacters(String wordStr){
if(wordStr != null && !"".equals(wordStr)){
String regEx="[`~!@#$%^&*()+=|{}':;',//[//].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(wordStr);
if(m.find()){
return "-1";
}
}
return "1";
}
几个String的处理方法。
最新推荐文章于 2022-03-25 09:59:45 发布