Class FileCopier

java.lang.Object
cloud.opencode.base.io.file.FileCopier

public final class FileCopier extends Object
File Copier Utility 文件复制器

Fluent API for copying files and directories with various options. Supports recursive copying and file attribute preservation.

用于复制文件和目录的流式API。 支持递归复制和文件属性保留。

Features | 主要功能:

  • Fluent API - 流式API
  • Recursive copy - 递归复制
  • Attribute preservation - 属性保留
  • Replace existing option - 替换现有文件选项

Usage Examples | 使用示例:

// Copy file
FileCopier.copy(source, target);

// Copy with replace
FileCopier.from(source).to(target).replaceExisting().execute();

// Copy directory recursively
FileCopier.from(sourceDir).to(targetDir).recursive().execute();

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
Since:
JDK 25, opencode-base-io V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • from

      public static FileCopier from(Path source)
      Creates a file copier from source 从源创建文件复制器
      Parameters:
      source - the source path | 源路径
      Returns:
      file copier | 文件复制器
    • from

      public static FileCopier from(String source)
      Creates a file copier from source string 从源字符串创建文件复制器
      Parameters:
      source - the source path string | 源路径字符串
      Returns:
      file copier | 文件复制器
    • copy

      public static Path copy(Path source, Path target)
      Copies a file directly 直接复制文件
      Parameters:
      source - the source path | 源路径
      target - the target path | 目标路径
      Returns:
      target path | 目标路径
    • copyReplace

      public static Path copyReplace(Path source, Path target)
      Copies a file with replace option 使用替换选项复制文件
      Parameters:
      source - the source path | 源路径
      target - the target path | 目标路径
      Returns:
      target path | 目标路径
    • to

      public FileCopier to(Path target)
      Sets the target path 设置目标路径
      Parameters:
      target - the target path | 目标路径
      Returns:
      this | 当前对象
    • to

      public FileCopier to(String target)
      Sets the target path string 设置目标路径字符串
      Parameters:
      target - the target path string | 目标路径字符串
      Returns:
      this | 当前对象
    • replaceExisting

      public FileCopier replaceExisting()
      Enables replace existing 启用替换现有文件
      Returns:
      this | 当前对象
    • copyAttributes

      public FileCopier copyAttributes()
      Enables copy attributes 启用复制属性
      Returns:
      this | 当前对象
    • recursive

      public FileCopier recursive()
      Enables recursive copy for directories 启用目录递归复制
      Returns:
      this | 当前对象
    • execute

      public Path execute()
      Executes the copy operation 执行复制操作
      Returns:
      target path | 目标路径
    • getSource

      public Path getSource()
      Gets the source path 获取源路径
      Returns:
      source path | 源路径
    • getTarget

      public Path getTarget()
      Gets the target path 获取目标路径
      Returns:
      target path | 目标路径