The use of java commons-io tool class

commons-io is a tool class written by third-party programmers, not a method brought by java itself. It is a tool class developed on the basis of the tool class provided by java. It simplifies the usage of the code and can improve the development efficiency.

usage

1. Download the jar package
2. Create a new lib directory in the program and put the jar package in it
3. Right click on the jar package, select build path, add to build path
insert image description here4. Use the method in the jar package in the code

package com.wowowo.io6;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

public class TestCommons_io {
    
    

	/**
	 * @param args
	 */
	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		
		String filename=FilenameUtils.getName("d:/aa/1.txt"); //返回文件名
		
		System.out.println(filename);
		
		String extname=FilenameUtils.getExtension("d:/aa/1.txt"); //返回文件的扩展名(后缀名)
		
		System.out.println(extname);
		
		System.out.println(FilenameUtils.isExtension("d:/aa/0.jpg", "jpg"));//判断文件后缀名
		
		
		long begin=System.currentTimeMillis();
		
		try {
    
    
			FileUtils.copyFile(new File("d:/aa/0.jpg"), new File("d:/aa/1.jpg"));
		} catch (IOException e) {
    
    
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		long end=System.currentTimeMillis();
		
		System.out.println("用工具包复制文件用时:"+(end-begin)+"毫秒");
		
	}

}

Guess you like

Origin blog.csdn.net/Rockandrollman/article/details/130395596