cn.hutool.core.io.FileUtil.copyFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(982)

本文整理了Java中cn.hutool.core.io.FileUtil.copyFile()方法的一些代码示例,展示了FileUtil.copyFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.copyFile()方法的具体详情如下:
包路径:cn.hutool.core.io.FileUtil
类名称:FileUtil
方法名:copyFile

FileUtil.copyFile介绍

[英]通过JDK7+的 Files#copy(Path,Path,CopyOption...) 方法拷贝文件
[中]通过JDK7+的 文件#复制(路径、路径、复制选项…)方法拷贝文件

代码示例

代码示例来源:origin: looly/hutool

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件路径
 * @param dest 目标文件或目录路径,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return File
 * @throws IORuntimeException IO异常
 */
public static File copyFile(String src, String dest, StandardCopyOption... options) throws IORuntimeException {
  Assert.notBlank(src, "Source File path is blank !");
  Assert.notNull(src, "Destination File path is null !");
  return copyFile(Paths.get(src), Paths.get(dest), options).toFile();
}

代码示例来源:origin: looly/hutool

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件路径
 * @param dest 目标文件或目录路径,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return File
 * @throws IORuntimeException IO异常
 */
public static File copyFile(String src, String dest, StandardCopyOption... options) throws IORuntimeException {
  Assert.notBlank(src, "Source File path is blank !");
  Assert.notNull(src, "Destination File path is null !");
  return copyFile(Paths.get(src), Paths.get(dest), options).toFile();
}

代码示例来源:origin: looly/hutool

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件
 * @param dest 目标文件或目录,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return 目标文件
 * @throws IORuntimeException IO异常
 */
public static File copyFile(File src, File dest, StandardCopyOption... options) throws IORuntimeException {
  // check
  Assert.notNull(src, "Source File is null !");
  if (false == src.exists()) {
    throw new IORuntimeException("File not exist: " + src);
  }
  Assert.notNull(dest, "Destination File or directiory is null !");
  if (equals(src, dest)) {
    throw new IORuntimeException("Files '{}' and '{}' are equal", src, dest);
  }
  return copyFile(src.toPath(), dest.toPath(), options).toFile();
}

代码示例来源:origin: looly/hutool

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件
 * @param dest 目标文件或目录,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return 目标文件
 * @throws IORuntimeException IO异常
 */
public static File copyFile(File src, File dest, StandardCopyOption... options) throws IORuntimeException {
  // check
  Assert.notNull(src, "Source File is null !");
  if (false == src.exists()) {
    throw new IORuntimeException("File not exist: " + src);
  }
  Assert.notNull(dest, "Destination File or directiory is null !");
  if (equals(src, dest)) {
    throw new IORuntimeException("Files '{}' and '{}' are equal", src, dest);
  }
  return copyFile(src.toPath(), dest.toPath(), options).toFile();
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件路径
 * @param dest 目标文件或目录路径,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return File
 * @throws IORuntimeException IO异常
 */
public static File copyFile(String src, String dest, StandardCopyOption... options) throws IORuntimeException {
  Assert.notBlank(src, "Source File path is blank !");
  Assert.notNull(src, "Destination File path is null !");
  return copyFile(Paths.get(src), Paths.get(dest), options).toFile();
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 通过JDK7+的 {@link Files#copy(Path, Path, CopyOption...)} 方法拷贝文件
 * 
 * @param src 源文件
 * @param dest 目标文件或目录,如果为目录使用与源文件相同的文件名
 * @param options {@link StandardCopyOption}
 * @return 目标文件
 * @throws IORuntimeException IO异常
 */
public static File copyFile(File src, File dest, StandardCopyOption... options) throws IORuntimeException {
  // check
  Assert.notNull(src, "Source File is null !");
  if (false == src.exists()) {
    throw new IORuntimeException("File not exist: " + src);
  }
  Assert.notNull(dest, "Destination File or directiory is null !");
  if (equals(src, dest)) {
    throw new IORuntimeException("Files '{}' and '{}' are equal", src, dest);
  }
  return copyFile(src.toPath(), dest.toPath(), options).toFile();
}

相关文章

微信公众号

最新文章

更多