Tools.java
上传用户:yunfeng252
上传日期:2022-07-23
资源大小:12403k
文件大小:2k
- package org.yufeng.utils;
- import java.io.File;
- import java.security.MessageDigest;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class Tools {
- public Tools() {
- }
- public static String getData() {
- Date date = new Date();
- SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String now = formater.format(date);
- return now;
- }
- public static String getDataByMD(String data) {
- String now = data.substring(5, 10);
- return now;
- }
- public static String separator(String url) {
- url += File.separator;
- return url;
- }
- public static String minPic(String basepic) {
- String minpic = "";
- int num = basepic.lastIndexOf(".");
- String temp = basepic.substring(num);
- String temp2 = basepic.substring(0, num);
- minpic += temp2 + "_min" + temp;
- return minpic;
- }
- public static String filterHtml(String s) {
- char c[] = s.toCharArray();
- char ch;
- StringBuffer buf = new StringBuffer();
- for (int i = 0, size = c.length; i < size; i++) {
- ch = c[i];
- if (ch == '"') {
- buf.append(""");
- } else if (ch == '&') {
- buf.append("&");
- } else if (ch == '<') {
- buf.append("<");
- } else if (ch == '>') {
- buf.append(">");
- } else if (ch == 'n') {
- buf.append("<br>");
- } else if (ch == ' ') {
- buf.append(" ");
- } else {
- buf.append(ch);
- }
- }
- c = null;
- return buf.toString();
- }
- // MD5加密
- public static String md5(String str) {
- String result = "";
- if (null != str) {
- try {
- MessageDigest m = MessageDigest.getInstance("MD5");
- m.update(str.getBytes("UTF8"));
- byte s[] = m.digest();
- for (int i = 0; i < s.length; i++) {
- result += Integer.toHexString(
- (0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
- }
- } catch (Exception e) {
- System.out.println("MD5加密错误!!");
- e.printStackTrace();
- result = null;
- }
- }
- return result;
- }
- public static void main(String[] args) {
- System.out.println(md5("admin"));
- }
- }