Class IOTool

java.lang.Object
com.xxl.tool.io.IOTool

public class IOTool extends Object
IO Tool
Author:
xuxueli 2024-10-27
  • Field Details

  • Constructor Details

    • IOTool

      public IOTool()
  • Method Details

    • copy

      public static int copy(InputStream input, OutputStream output) throws IOException
      copy from InputStream to OutputStream, close both streams when done.
      Parameters:
      input - InputStream
      output - OutputStream
      Returns:
      the number of bytes copied
      Throws:
      IOException - in case of I/O errors
    • copy

      public static int copy(InputStream input, OutputStream output, boolean closeInput, boolean closeOutput) throws IOException
      copy from InputStream to OutputStream,
      Parameters:
      input - InputStream
      output - OutputStream
      closeInput - true to close input stream when done; false to keep it open
      closeOutput - true to close output stream when done; false to keep it open
      Returns:
      the number of bytes copied
      Throws:
      IOException - in case of I/O errors
    • copy

      public static void copy(byte[] input, OutputStream output) throws IOException
      copy from InputStream to OutputStream 1、will close output streams when done.
      Parameters:
      input - the byte array
      output - OutputStream
      Throws:
      IOException - in case of I/O errors
    • copy

      public static void copy(byte[] input, OutputStream output, boolean closeOutput) throws IOException
      copy from InputStream to OutputStream
      Parameters:
      input - the byte array
      output - OutputStream
      closeOutput - true to close output streams when done; false to keep them open
      Throws:
      IOException - in case of I/O errors
    • close

      public static void close(Closeable closeable)
      close the supplied Closeable, ignore exceptions
      Parameters:
      closeable - the Closeable to close
    • readBytes

      public static byte[] readBytes(InputStream inputStream) throws IOException
      read byte[] from InputStream 1、closes the stream when done.
      Parameters:
      inputStream - input stream
      Returns:
      read byte[]
      Throws:
      IOException
    • readString

      public static String readString(InputStream inputStream) throws IOException
      read string contents from InputStream 1、closes the stream when done.
      Parameters:
      inputStream - input stream
      Returns:
      read string
      Throws:
      IOException
    • readString

      public static String readString(InputStream inputStream, Charset charset) throws IOException
      read string contents from InputStream 1、closes the stream when done.
      Parameters:
      inputStream - input stream
      charset - charset encoding
      Returns:
      read string
      Throws:
      IOException
    • writeString

      public static void writeString(String data, OutputStream output) throws IOException
      write string 2 OutputStream
      Parameters:
      data - string data
      output - output stream
      Throws:
      IOException - exception
    • writeString

      public static void writeString(String data, OutputStream output, Charset charset) throws IOException
      write string 2 OutputStream
      Parameters:
      data - string data
      output - output stream
      charset - charset encoding
      Throws:
      IOException - in case of I/O errors
    • newBufferedWriter

      public static BufferedWriter newBufferedWriter(File file, boolean append) throws IOException
      build new writer
      Parameters:
      file - file to write
      append - true if append, false will override
      Returns:
      writer
      Throws:
      IOException
    • newBufferedWriter

      public static BufferedWriter newBufferedWriter(File file, boolean append, Charset charset, int bufferSize) throws IOException
      build new writer
      Parameters:
      file - file to write
      append - true if append, false will override
      charset - charset to write
      bufferSize - buffer size
      Returns:
      writer
      Throws:
      IOException