org.apache.commons.io.FileUtils.copyToFile()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(885)

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

FileUtils.copyToFile介绍

[英]Copies bytes from an InputStream source to a file destination. The directories up to destination will be created if they don't already exist. destination will be overwritten if it already exists. The source stream is left open, e.g. for use with java.util.zip.ZipInputStream. See #copyInputStreamToFile(InputStream,File) for a method that closes the input stream.
[中]将字节从输入流source复制到文件destination。如果目录不存在,则将创建高达destination的目录。destination如果已经存在,将被覆盖。源流保持打开状态,例如与java一起使用。util。拉链ZipInputStream。有关关闭输入流的方法,请参见#copyInputStreamToFile(InputStream,File)。

代码示例

代码示例来源:origin: commons-io/commons-io

/**
 * Copies bytes from an {@link InputStream} <code>source</code> to a file
 * <code>destination</code>. The directories up to <code>destination</code>
 * will be created if they don't already exist. <code>destination</code>
 * will be overwritten if it already exists.
 * The {@code source} stream is closed.
 * See {@link #copyToFile(InputStream, File)} for a method that does not close the input stream.
 *
 * @param source      the <code>InputStream</code> to copy bytes from, must not be {@code null}, will be closed
 * @param destination the non-directory <code>File</code> to write bytes to
 *                    (possibly overwriting), must not be {@code null}
 * @throws IOException if <code>destination</code> is a directory
 * @throws IOException if <code>destination</code> cannot be written
 * @throws IOException if <code>destination</code> needs creating but can't be
 * @throws IOException if an IO error occurs during copying
 * @since 2.0
 */
public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException {
  try (InputStream in = source) {
    copyToFile(in, destination);
  }
}

代码示例来源:origin: gocd/gocd

public void copyTo(File output) throws IOException {
    try (InputStream in = source.getInputStream()) {
      FileUtils.copyToFile(in, output);
    }
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Copies bytes from an {@link InputStream} <code>source</code> to a file
 * <code>destination</code>. The directories up to <code>destination</code>
 * will be created if they don't already exist. <code>destination</code>
 * will be overwritten if it already exists.
 * The {@code source} stream is closed.
 * See {@link #copyToFile(InputStream, File)} for a method that does not close the input stream.
 *
 * @param source      the <code>InputStream</code> to copy bytes from, must not be {@code null}, will be closed
 * @param destination the non-directory <code>File</code> to write bytes to
 *                    (possibly overwriting), must not be {@code null}
 * @throws IOException if <code>destination</code> is a directory
 * @throws IOException if <code>destination</code> cannot be written
 * @throws IOException if <code>destination</code> needs creating but can't be
 * @throws IOException if an IO error occurs during copying
 * @since 2.0
 */
public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException {
  try (InputStream in = source) {
    copyToFile(in, destination);
  }
}

代码示例来源:origin: com.github.binarywang/weixin-java-common

/**
 * 创建临时文件.
 *
 * @param inputStream 输入文件流
 * @param name        文件名
 * @param ext         扩展名
 * @param tmpDirFile  临时文件夹目录
 */
public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException {
 File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile);
 resultFile.deleteOnExit();
 org.apache.commons.io.FileUtils.copyToFile(inputStream, resultFile);
 return resultFile;
}

代码示例来源:origin: binarywang/WxJava

/**
 * 创建临时文件.
 *
 * @param inputStream 输入文件流
 * @param name        文件名
 * @param ext         扩展名
 * @param tmpDirFile  临时文件夹目录
 */
public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException {
 File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile);
 resultFile.deleteOnExit();
 org.apache.commons.io.FileUtils.copyToFile(inputStream, resultFile);
 return resultFile;
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Copies bytes from an {@link InputStream} <code>source</code> to a file
 * <code>destination</code>. The directories up to <code>destination</code>
 * will be created if they don't already exist. <code>destination</code>
 * will be overwritten if it already exists.
 * The {@code source} stream is closed.
 * See {@link #copyToFile(InputStream, File)} for a method that does not close the input stream.
 *
 * @param source      the <code>InputStream</code> to copy bytes from, must not be {@code null}, will be closed
 * @param destination the non-directory <code>File</code> to write bytes to
 *                    (possibly overwriting), must not be {@code null}
 * @throws IOException if <code>destination</code> is a directory
 * @throws IOException if <code>destination</code> cannot be written
 * @throws IOException if <code>destination</code> needs creating but can't be
 * @throws IOException if an IO error occurs during copying
 * @since 2.0
 */
public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException {
  try {
    copyToFile(source, destination);
  } finally {
    IOUtils.closeQuietly(source);
  }
}

代码示例来源:origin: org.sonarsource.typescript/sonar-typescript-plugin

public static void extract(InputStream bundle, File destination) throws IOException {
  ZipInputStream zip = new ZipInputStream(bundle);
  ZipEntry entry = zip.getNextEntry();
  if (entry == null) {
   throw new IllegalStateException("At least one entry expected.");
  }
  while (entry != null) {
   File entryDestination = new File(destination, entry.getName());
   if (entry.isDirectory()) {
    entryDestination.mkdirs();
   } else {
    FileUtils.copyToFile(zip, entryDestination);
   }
   zip.closeEntry();
   entry = zip.getNextEntry();
  }
 }
}

代码示例来源:origin: omegat-org/omegat

FileUtils.copyToFile(zis, f);
extracted.add(entry.getName());

代码示例来源:origin: org.codehaus.izpack/izpack-util

FileUtils.copyToFile(in, new File(sandbox, pathname));

代码示例来源:origin: gsvigruha/cosyan

public void restore(String name) throws IOException, DBException {
  MetaWriter metaWriter = metaRepo.metaRepoWriteLock();
  try {
   FileUtils.deleteDirectory(new File(config.tableDir()));
   FileUtils.deleteDirectory(new File(config.indexDir()));
   FileUtils.deleteDirectory(new File(config.metaDir()));
   FileUtils.forceDelete(new File(config.usersFile()));

   Files.createDirectories(Paths.get(config.tableDir()));
   Files.createDirectories(Paths.get(config.indexDir()));
   Files.createDirectories(Paths.get(config.metaDir()));
   Files.createDirectories(Paths.get(config.metaTableDir()));
   Files.createDirectories(Paths.get(config.metaViewDir()));

   ZipInputStream stream = new ZipInputStream(
     Files.newInputStream(Paths.get(config.backupDir() + File.separator + name)));
   try {
    ZipEntry entry;
    while ((entry = stream.getNextEntry()) != null) {
     FileUtils.copyToFile(stream, new File(config.dataDir() + File.separator + entry.getName()));
    }
   } finally {
    stream.close();
   }
   metaWriter.resetAndReadTables();
  } finally {
   metaWriter.metaRepoWriteUnlock();
  }
 }
}

相关文章

FileUtils类方法