1 1、日期格式化
2 Date date=new Date();
3 //转换成时间格式12小时制
4 SimpleDateFormat df_12=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
5
6 //转换成时间格式24小时制
7 SimpleDateFormat df_24=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
8
9 System.out.println("12小时制时间::"+df_12.format(date));
10 System.out.println("24小时制时间::"+df_24.format(date));
11
12
13 2、过滤文件名非法字符
14 private static Pattern FilePattern = Pattern.compile("[\\\\/:*?\"<>|]");
15 public static String filenameFilter(String str) {
16 return str==null?null:FilePattern.matcher(str).replaceAll("");
17 }
18
19 3、读取文件内容
20 public static String readFile(String filePath) throws Exception{
21 File file = new File(filePath);
22 BufferedReader in = null;
23 String result = "";
24 String str = "";
25 try {
26 in = new BufferedReader(new FileReader(file));
27 while((str = in.readLine()) != null){
28 result += str;
29 }
30 in.close();
31 } catch (Exception e) {
32 e.printStackTrace();
33 }
34 return result;
35 }
36