读取properties文件
public static void loadConfiguration() {
Properties properties = new Properties();
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("src/main/resources/config.properties"));
properties.load(bufferedReader);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ConfigConstants.CHROME_PATH = properties.getProperty("chromePath");
ConfigConstants.SAMPLE_WEIGHT = Integer.parseInt(properties.getProperty("sampleWeight"));
ConfigConstants.LAST_LENGTH = Integer.parseInt(properties.getProperty("lastLength"));
}
获取当前日期
/**
*
* @param dateDifference: 时间偏移,昨天为-1,今天为0
* pattern: 样式字符串
*
* @return 时间字符串
*
* @description 方法描述: 使用日历类,获取当期日期
*
* @author jusang
*
* @date 2020/2/28 10:19
*/
public static String getCurrentDate(int dateDifference, String pattern ){
Calendar cal= Calendar.getInstance();
cal.add(Calendar.DATE,dateDifference);
Date d=cal.getTime();
SimpleDateFormat sf=new SimpleDateFormat(pattern);
return sf.format(d);
}
public static String getDay(){
return getCurrentDate(0, "yyyy" + "年" + "MM" + "月" + "dd"+"日");
}
字符串转拼音
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
public class PinyinUtil {
public static String word2PinYin(String word){
String pinyin = "";
char[] newChar = word.toCharArray();
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < newChar.length; i++) {
if (newChar[i] > 128) {
try {
pinyin += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0];
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
}else{
pinyin += newChar[i];
}
}
return pinyin;
}
public static void main(String[] args) {
str = word2PinYin("天下第一");
System.out.println(str);
}
}
中文数字转阿拉伯数字
代码有点长,参考这个链接。可以实现将中文数字转换为阿拉伯数字,以及将一句话中的中文转成阿拉伯数字