关闭

Java工具方法hutool 使用备注

1879人阅读 评论(0) 收藏 举报
分类:
package TestHuTool;

import it.sauronsoftware.cron4j.Scheduler;

import java.io.File;

import com.xiaoleilu.hutool.NetUtil;
import com.xiaoleilu.hutool.RandomUtil;
import com.xiaoleilu.hutool.SecureUtil;
import com.xiaoleilu.hutool.Setting;
import com.xiaoleilu.hutool.Validator;

/**

Java工具方法hutool 使用例子
http://hutool.mydoc.io/
http://hutool.mydoc.io/?t=820
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        
        System.out.println(NetUtil.localIpv4s());
        //System.out.println(NetUtil.isUsableLocalPort(9090));
        String charset="utf-8";
        System.out.println(RandomUtil.randomString(10));
        String source="fuck";
        System.out.println(SecureUtil.md5(source, "utf-8"));
        System.out.println(SecureUtil.sha1(source, "utf-8"));
        String out=SecureUtil.base64(source, "utf-8");
        System.out.println(out);
        System.out.println(SecureUtil.decodeBase64(out, "utf-8"));
        Setting setting=new Setting(new File("d:/cmd.ini"), charset, true);
        System.out.println(setting.getString("command.cmd"));
        
        boolean isEmail = Validator.isEmail("loolly@gmail.com");
        System.out.println(isEmail);
        
        System.out.println(Validator.isByRegex("需要验证字段的正则表达式", "被验证内容"));
        
        //定时器任务http://hutool.mydoc.io/?t=827
        	
        //使用cron4j框架
        System.out.println(new File(".").getAbsolutePath());
        //CronUtil.setCronSetting("cron4j.setting");
       // CronUtil.start();
        
     // Declares the file.
		File file = new File("cron4jtab.txt");
		// Creates the scheduler.
		Scheduler scheduler = new Scheduler();
		// Schedules the file.
		scheduler.scheduleFile(file);
		// Starts the scheduler.
		scheduler.start();
		// Stays alive for five minutes.
		try {
			Thread.sleep(5L * 60L * 1000L);
		} catch (InterruptedException e) {
			;
		}
		// Stops the scheduler.
		scheduler.stop();
        
        
    }
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>TestHuTool</groupId>
	<artifactId>TestHuTool</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>TestHuTool</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.xiaoleilu</groupId>
			<artifactId>hutool</artifactId>
			<version>2.9.2</version>
		</dependency>
		<dependency>
			<groupId>it.sauronsoftware.cron4j</groupId>
			<artifactId>cron4j</artifactId>
			<version>2.2.5</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.12</version>
		</dependency>
	</dependencies>
</project>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1794767次
    • 积分:25449
    • 等级:
    • 排名:第242名
    • 原创:783篇
    • 转载:382篇
    • 译文:0篇
    • 评论:225条
    我的技术博客
    最新评论