Search in sources :

Example 1 with CopyVisitor

use of cn.hutool.core.io.file.visitor.CopyVisitor in project hutool by looly.

the class PathUtil method copyContent.

/**
 * 拷贝目录下的所有文件或目录到目标目录中,此方法不支持文件对文件的拷贝。
 * <ul>
 *     <li>源文件为目录,目标也为目录或不存在,则拷贝目录下所有文件和目录到目标目录下</li>
 *     <li>源文件为文件,目标为目录或不存在,则拷贝文件到目标目录下</li>
 * </ul>
 *
 * @param src     源文件路径,如果为目录只在目标中创建新目录
 * @param target  目标目录,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return Path
 * @throws IORuntimeException IO异常
 * @since 5.5.1
 */
public static Path copyContent(Path src, Path target, CopyOption... options) throws IORuntimeException {
    Assert.notNull(src, "Src path must be not null !");
    Assert.notNull(target, "Target path must be not null !");
    try {
        Files.walkFileTree(src, new CopyVisitor(src, target, options));
    } catch (IOException e) {
        throw new IORuntimeException(e);
    }
    return target;
}
Also used : IORuntimeException(cn.hutool.core.io.IORuntimeException) CopyVisitor(cn.hutool.core.io.file.visitor.CopyVisitor) IOException(java.io.IOException)

Aggregations

IORuntimeException (cn.hutool.core.io.IORuntimeException)1 CopyVisitor (cn.hutool.core.io.file.visitor.CopyVisitor)1 IOException (java.io.IOException)1