zoukankan      html  css  js  c++  java
  • JAVA快速功能

     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  
  • 相关阅读:
    队列
    栈的链式存储
    单例和多例设计模式
    顺序栈的基本操作
    串的模式匹配
    线性表的链式存储结构
    倒置顺序表
    回文序列
    go语言系列-从运算符到函数
    go语言系列-从零到数据类型
  • 原文地址:https://www.cnblogs.com/guoyinli/p/8553528.html
Copyright © 2011-2022 走看看