Package com.xxl.tool.io
Class IOTool
java.lang.Object
com.xxl.tool.io.IOTool
IO Tool
- Author:
- xuxueli 2024-10-27
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose the suppliedCloseable, ignore exceptionsstatic voidcopy(byte[] input, OutputStream output) copy from InputStream to OutputStream 1、will close output streams when done.static voidcopy(byte[] input, OutputStream output, boolean closeOutput) copy from InputStream to OutputStreamstatic intcopy(InputStream input, OutputStream output) copy from InputStream to OutputStream, close both streams when done.static intcopy(InputStream input, OutputStream output, boolean closeInput, boolean closeOutput) copy from InputStream to OutputStream,static BufferedWriternewBufferedWriter(File file, boolean append) build new writerstatic BufferedWriternewBufferedWriter(File file, boolean append, Charset charset, int bufferSize) build new writerstatic byte[]readBytes(InputStream inputStream) read byte[] from InputStream 1、closes the stream when done.static StringreadString(InputStream inputStream) read string contents from InputStream 1、closes the stream when done.static StringreadString(InputStream inputStream, Charset charset) read string contents from InputStream 1、closes the stream when done.static voidwriteString(String data, OutputStream output) write string 2 OutputStreamstatic voidwriteString(String data, OutputStream output, Charset charset) write string 2 OutputStream
-
Field Details
-
BUFFER_SIZE
public static final int BUFFER_SIZEdefault buffer size- See Also:
-
-
Constructor Details
-
IOTool
public IOTool()
-
-
Method Details
-
copy
copy from InputStream to OutputStream, close both streams when done.- Parameters:
input- InputStreamoutput- 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- InputStreamoutput- OutputStreamcloseInput- true to close input stream when done; false to keep it opencloseOutput- 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
copy from InputStream to OutputStream 1、will close output streams when done.- Parameters:
input- the byte arrayoutput- OutputStream- Throws:
IOException- in case of I/O errors
-
copy
copy from InputStream to OutputStream- Parameters:
input- the byte arrayoutput- OutputStreamcloseOutput- true to close output streams when done; false to keep them open- Throws:
IOException- in case of I/O errors
-
close
close the suppliedCloseable, ignore exceptions- Parameters:
closeable- theCloseableto close
-
readBytes
read byte[] from InputStream 1、closes the stream when done.- Parameters:
inputStream- input stream- Returns:
- read byte[]
- Throws:
IOException
-
readString
read string contents from InputStream 1、closes the stream when done.- Parameters:
inputStream- input stream- Returns:
- read string
- Throws:
IOException
-
readString
read string contents from InputStream 1、closes the stream when done.- Parameters:
inputStream- input streamcharset- charset encoding- Returns:
- read string
- Throws:
IOException
-
writeString
write string 2 OutputStream- Parameters:
data- string dataoutput- 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 dataoutput- output streamcharset- charset encoding- Throws:
IOException- in case of I/O errors
-
newBufferedWriter
build new writer- Parameters:
file- file to writeappend- 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 writeappend- true if append, false will overridecharset- charset to writebufferSize- buffer size- Returns:
- writer
- Throws:
IOException
-