类 FileCopyUtils

java.lang.Object
cn.taketoday.util.FileCopyUtils

public abstract class FileCopyUtils extends Object
Simple utility methods for file and stream copying. All copy methods use a block size of 4096 bytes, and close all affected streams when done. A variation of the copy methods from this class that leave streams open can be found in StreamUtils.

Mainly for use within the framework, but also useful for application code.

从以下版本开始:
4.0 2021/8/21 00:04
作者:
Juergen Hoeller, Hyunjin Choi, Harry Yang
另请参阅:
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final int
    The default buffer size used when copying bytes.
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    private static void
    close(Closeable closeable)
    Attempt to close the supplied Closeable, silently swallowing any exceptions.
    static void
    copy(byte[] in, File out)
    Copy the contents of the given byte array to the given output File.
    static void
    copy(byte[] in, OutputStream out)
    Copy the contents of the given byte array to the given OutputStream.
    static int
    copy(File in, File out)
    Copy the contents of the given input File to the given output File.
    static int
    Copy the contents of the given InputStream to the given OutputStream.
    static int
    copy(Reader in, Writer out)
    Copy the contents of the given Reader to the given Writer.
    static int
    copy(Reader in, Writer out, int bufferSize)
    Copy the contents of the given Reader to the given Writer.
    static void
    copy(String in, Writer out)
    Copy the contents of the given String to the given Writer.
    static byte[]
    Copy the contents of the given input File into a new byte array.
    static byte[]
    Copy the contents of the given InputStream into a new byte array.
    static String
    Copy the contents of the given Reader into a String.
    static String
    copyToString(Reader in, int bufferSize)
    Copy the contents of the given Reader into a String.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • BUFFER_SIZE

      public static final int BUFFER_SIZE
      The default buffer size used when copying bytes.
      另请参阅:
  • 构造器详细资料

    • FileCopyUtils

      public FileCopyUtils()
  • 方法详细资料

    • copy

      public static int copy(File in, File out) throws IOException
      Copy the contents of the given input File to the given output File.
      参数:
      in - the file to copy from
      out - the file to copy to
      返回:
      the number of bytes copied
      抛出:
      IOException - in case of I/O errors
    • copy

      public static void copy(byte[] in, File out) throws IOException
      Copy the contents of the given byte array to the given output File.
      参数:
      in - the byte array to copy from
      out - the file to copy to
      抛出:
      IOException - in case of I/O errors
    • copyToByteArray

      public static byte[] copyToByteArray(File in) throws IOException
      Copy the contents of the given input File into a new byte array.
      参数:
      in - the file to copy from
      返回:
      the new byte array that has been copied to
      抛出:
      IOException - in case of I/O errors
    • copy

      public static int copy(InputStream in, OutputStream out) throws IOException
      Copy the contents of the given InputStream to the given OutputStream. Closes both streams when done.
      参数:
      in - the stream to copy from
      out - the stream to copy to
      返回:
      the number of bytes copied
      抛出:
      IOException - in case of I/O errors
    • copy

      public static void copy(byte[] in, OutputStream out) throws IOException
      Copy the contents of the given byte array to the given OutputStream. Closes the stream when done.
      参数:
      in - the byte array to copy from
      out - the OutputStream to copy to
      抛出:
      IOException - in case of I/O errors
    • copyToByteArray

      public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException
      Copy the contents of the given InputStream into a new byte array. Closes the stream when done.
      参数:
      in - the stream to copy from (may be null or empty)
      返回:
      the new byte array that has been copied to (possibly empty)
      抛出:
      IOException - in case of I/O errors
    • copy

      public static int copy(Reader in, Writer out) throws IOException
      Copy the contents of the given Reader to the given Writer. Closes both when done.
      参数:
      in - the Reader to copy from
      out - the Writer to copy to
      返回:
      the number of characters copied
      抛出:
      IOException - in case of I/O errors
    • copy

      public static int copy(Reader in, Writer out, int bufferSize) throws IOException
      Copy the contents of the given Reader to the given Writer. Closes both when done.
      参数:
      in - the Reader to copy from
      out - the Writer to copy to
      bufferSize - user specified buffer size
      返回:
      the number of characters copied
      抛出:
      IOException - in case of I/O errors
    • copy

      public static void copy(String in, Writer out) throws IOException
      Copy the contents of the given String to the given Writer. Closes the writer when done.
      参数:
      in - the String to copy from
      out - the Writer to copy to
      抛出:
      IOException - in case of I/O errors
    • copyToString

      public static String copyToString(@Nullable Reader in) throws IOException
      Copy the contents of the given Reader into a String. Closes the reader when done.
      参数:
      in - the reader to copy from (may be null or empty)
      返回:
      the String that has been copied to (possibly empty)
      抛出:
      IOException - in case of I/O errors
    • copyToString

      public static String copyToString(@Nullable Reader in, int bufferSize) throws IOException
      Copy the contents of the given Reader into a String. Closes the reader when done.
      参数:
      in - the reader to copy from (may be null or empty)
      bufferSize - user specified buffer size
      返回:
      the String that has been copied to (possibly empty)
      抛出:
      IOException - in case of I/O errors
    • close

      private static void close(@Nullable Closeable closeable)
      Attempt to close the supplied Closeable, silently swallowing any exceptions.
      参数:
      closeable - the Closeable to close