JAVA快速功能
2024-08-28 16:29:41
1、日期格式化
Date date=new Date();
//转换成时间格式12小时制
SimpleDateFormat df_12=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //转换成时间格式24小时制
SimpleDateFormat df_24=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("12小时制时间::"+df_12.format(date));
System.out.println("24小时制时间::"+df_24.format(date)); 2、过滤文件名非法字符
private static Pattern FilePattern = Pattern.compile("[\\\\/:*?\"<>|]");
public static String filenameFilter(String str) {
return str==null?null:FilePattern.matcher(str).replaceAll("");
} 3、读取文件内容
public static String readFile(String filePath) throws Exception{
File file = new File(filePath);
BufferedReader in = null;
String result = "";
String str = "";
try {
in = new BufferedReader(new FileReader(file));
while((str = in.readLine()) != null){
result += str;
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
最新文章
- C#的委托
- [LeetCode] Palindrome Number 验证回文数字
- 移动端web app自适应布局探索与总结
- UVa11324 The Largest Clique(强连通分量+缩点+记忆化搜索)
- Java 14 类型信息
- java反射机制浅谈
- WPF样式——多条件触发器
- IE7下position:relative的问题
- 运行批处理bat文件不出现黑框
- js多物体任意值运动
- 读书笔记—CLR via C#线程25-26章节
- Java Reference 源码分析
- Java字符串String
- C++11并发——多线程std::mutex (二)
- 管理 Oracle Cluster Registry(OCR)
- Delphi的程序单元、结构、基础知识(转)
- OPML文件
- vim相关命令单独记载
- tp3.2和Bootstrap模态框导入excel表格数据
- python教程(一)&#183;python环境搭建