In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail the example analysis of byte stream and character stream commonly used in java IO stream. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
one。 Classification of main IO flows
According to the figure, the main IO stream in java is divided into character stream and byte stream according to the different data types, and input stream and output stream according to the different data flow.
two。 Working with scen
1. Consider what the original data format is:
Scene one. The original data is binary or plain text and is used in the following ways:
(1)。 Binary format (as long as it is not certain to be plain text): InputStream,OutputStream and its subclasses (byte streams).
(2)。 Plain text format (including plain English and Chinese characters or other encoding methods): Reader,Writer and its subclasses (character stream).
Scenario 2: IO data channel:
(1)。 Enter: a subclass of the Reader,InputStream type.
(2)。 Output: a subclass of type Writer,OutputStream.
Scenario 3: IO flow conversion:
(1)。 Byte to character: InputStreamReader
(2)。 Character to byte: OutputStreamWriter
Scenario 4: data source flow direction:
(1)。 File: FileInputStream,FileOutputStream; FileReader,FileWriter
(2)。 Byte []: ByteArrayInputStream, ByteArrayOutputStream
(3) .Char []: CharArrayReader,CharArrayWriter
(4) .string: StringBufferInputStream,StringBufferOutputStream;StringReader,StringWriter
(5)。 Network data flow: InputStream,OutputStream;Reader,Writer
Scenario 5: buffering: (pay attention to whether readLine () is defined, and what more special input or output methods than read () and writer ())
To buffer: BufferedInputStream, BufferedOutputStream; BufferedReader, BufferedWriter
Scenario 6: formatted output:
Formatted output: PrintStream, PrintWriter
three。 Common methods of main byte stream
(1) .InputStream byte stream
/ / read the next byte of data from the input stream abstract int read () / / read a certain number of bytes from the input stream And store it in the buffer array b int read (byte [] b) / / read up to len bytes in the input stream into the byte array int read (byte [] b, int off, int len) / / skip and discard n bytes long skip (long n) / / close the input stream and release all system resources associated with the stream void close ()
(2) .OutputStream byte stream
/ / write b.length bytes from the specified byte array to this output stream void write (byte [] b) / / write the len bytes from the specified byte array starting from the offset off to this output stream void write (byte [] b, int off Int len) / / writes the specified bytes to this output stream abstract void write (int b) / / closes the output stream and releases all system resources associated with the stream void close () / / refreshes the output stream and forces all buffered output bytes void flush ()
four。 Common methods of main character stream
(1)。 Reader
/ / read a single character int read () / / read a character into an array int read (char [] cbuf) / / read a character into a part of the array abstract int read (char [] cbuf, int off, int len) / / skip the character long skip (long n) / / close the stream and release all resources associated with it abstract void close ()
(2)。 Writer
/ / write character array void write (char [] cbuf) / / write part of character array abstract void write (char [] cbuf, int off, int len) / / write single character void write (int c) / / write string void write (String str) / / write part of string void write (String str, int off) Int len) / / add the specified character to this writer Writer append (char c) / / add the specified character sequence to this writer Writer append (CharSequence csq) / / add a subsequence of the specified character sequence to this writer.Appendable Writer append (CharSequence csq, int start, int end) / / close the stream But first to refresh it abstract void close () / / refresh the stream buffer abstract void flush () on the "java IO stream commonly used operation of byte flow and character flow example analysis" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.