FileUtils快速方便拷贝文件

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

import org.apache.commons.io.FileUtils;
public class TestIO
{
    public static void main(String[] args)
    {
        try
        {
            File source = new File("D:/imagetmp/tp-20101028-00001");
            File destinationDir = new File("D:/grid");
            String sourceFileName = source.getName();
            File destination = new File(destinationDir + File.separator
                    + sourceFileName);
            if (!destination.exists())
            {
                destination.mkdirs();
            }
            File[] files = source.listFiles();
            for (File file : files)
            {
                FileUtils.copyFileToDirectory(file, destination);
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(Java,Apache)