Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the specific basic knowledge of Java IPUBO system?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What are the specific basic knowledge of Java I Pot O system? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

The abstract concept of stream is often used in the iWeiao class library of programming languages, which represents any data source object that has the ability to generate data or a receiver object that has the ability to receive data. The concept of "stream" is derived from the concept of pipe in UNIX. In UNIX, a pipeline is an uninterrupted byte stream, which is used to realize the communication between programs or processes, or to read and write peripherals, external files, and so on. It shields the details of data processing in the actual Imax O device. A stream must have a source and a destination, which can be areas of computer memory, disk files, or even a URL on Internet. The direction of the stream is important. According to the direction of the stream, the stream can be divided into two categories: the input stream and the output stream. In fact, input / output is intended for memory. In fact, the source end and destination end of the stream can be simply regarded as the producers and consumers of bytes. For the input stream, you don't have to care about what its source end is, but simply read the data from the stream, while for the output stream, you don't know its destination and simply write data to the stream.

a. Stream: an ordered sequence of data.

B-byte stream: the smallest data unit in a data stream is bytes.

c. Character stream: the smallest data unit in a data stream is a character.

one。 Classes in the java.io package correspond to two types of flows

One type of stream reads or writes directly from a specified location (such as a disk file or memory area). This type of stream is called node flow, and the other stream is called filter flow (wrapper flow).

Filter streams: some streams can receive bytes from files and other places, while others can combine bytes into more useful data types. The construction method of passing an existing stream to another stream, combining the two streams, the combined flow is called a filtered flow. The filter input stream often takes other input streams as its input source, which is filtered or processed and then provided to the user in the form of a new input stream, and the filter output stream is similar. We rarely use a single class to create flow objects, but instead provide the desired functionality (that is, the decorator design pattern) by superimposing multiple objects.

The common input and output streams of java actually inherit from four abstract classes, which are:

Single-byte-based InputStream,OutputStream class (byte-oriented iUnix O)

Reader, Writer classes based on double-byte Unicode code units (character-oriented Icando O)

Once the input stream is opened, the program can read data serially from the input stream. The process of reading / writing data from the input stream is generally as follows: open a stream channel-- > read / write information-- > close the stream channel.

In the java platform, there are two ways to obtain the character encoding type of the local platform:

(a) System.getProperty ("file.encoding")

(B) Charset cs=Charset.defaultCharset ()

All input streams and output streams can be divided into byte (input, output) streams, character (input, output) streams, mainly (OutputStream/InputStream) series for dealing with bytes, and (Reader/Write) series for dealing with characters.

two。 A Byte-oriented input stream (InputStream series), all of which can be connected to FileInputStream objects to provide a useful interface:

ByteArrayInputStream: use a buffer in memory as an InputStream

StringBufferInputStream (deprecated in java1.1): use a String object as an InputStream, and the underlying implementation uses StringBuffer

FileInputStream: read a file (file name, file, FileDescriptor object) by using a file as an InputStream

PipedInputStream: implements the concept of pipe, which is mainly used in threads (as a data source in multiple processes)

SequenceInputStream: merge multiple InputStream into a single InputStream

Byte (Byte) oriented output streams (OutputStream series) that can be connected to FilterOutputStream objects to provide a useful interface:

ByteArrayOutputStream: create a buffer in memory and store the information in a buffer in memory. Buffer initialization size (optional)

FileOutputStream: store information in a file (file name, file, FileDescriptor)

PipedOutputStream: implements the concept of pipe, mainly used in threads (specifying the destination of data for multithreading)

three。 Corresponding (Reader/Writer) series:

Reader: corresponding to InputStream, adapter InputStreamReader

Writer: corresponding to OutputStream, the adapter is OutputStreamWriter

FileReader: corresponding to FileOutputStream

FileWriter: corresponding to FileOurputStream

StringReader: no corresponding class

StringWriter: corresponding to ByteArrayInputStream

CharArrayReader: corresponding to ByteArrayOutputStream

CharArrayWriter: corresponding to ByteArrayOutputStream

PipedReader: corresponding to PipedInputStream

PipedWriter: corresponding to PipedOutputStream

four。 Conversion between two undirected stream (using adapter classes)

InputStreamReader and OutputStreamReader: convert a byte-oriented stream into a character-oriented stream.

InputStreamReader is a bridge between bytes and character streams: it reads bytes and decodes them into characters using the specified charset. The character set it uses can be specified by name or explicitly given, or it can accept the default character set of the platform.

OutputStreamWriter is a bridge between character flow and byte stream: characters to be written into the stream can be encoded into bytes using a specified charset. The character set it uses can be specified by name or explicitly given, otherwise the platform default character set will be accepted.

five。 Read data from InputStream through FilterInputStream:

DataInputStream: reads basic type (int, char,long, etc.) data from stream.

BufferedInputStream: use a buffer to prevent the actual read operation from having to take place every time it is read

LineNumberInputStream: records the number of lines in the input stream, and then calls getLineNumber () and setLineNumber (int)

PushbackInputStream: rarely used, generally used for compiler development

Write to OutputStream through FilterOutputStream:

DataIOutputStream: data of basic types (int, char,long, etc.) can be exported to stream according to the migration method.

BufferedOutputStream: use buffers to avoid actual writes every time data is sent

PrintStream: generates formatted output, in which DataOutputStream handles data storage and PrintStream processes display

six。 Change the behavior of the flow

Although BufferedOutputStream is a subclass of FilterOutputStream, BufferedWriter is not a subclass of FilterWriter. (FilterWriter is an abstract class without any subclasses)

There is no class corresponding to DataInputStream. Use DataInputStream unless you want to use BufferedReader instead of readLine ()

BufferedReader: corresponding to BufferedInputStream

LineNumberReader: corresponding to LineNumberInputStream

PushBackReader: corresponding to PushbackInputStream

BufferedWrite: corresponding to BufferedOutStream

PrintWrite: corresponding to PrintStream

seven。 Self-independent class: RandomAccessFile

This class is suitable for files made up of records of known size. RandomAccessFile, in addition to implementing the DataInput and DataOutput interfaces (DataInputStream and DataOutputStream also implement these two interfaces), this class is a completely independent class that has essentially different behavior from other Isign O types and can be moved forward and backward within a file, directly derived from Object.

You can read and write a file through the RandomAccessFile object

When generating an object, you can indicate the nature of the file to be opened: r, read-only; w, write-only; rw read-write

You can jump directly to the location specified in the file

Most (but not all) of the functions of RandomAccessFile are replaced by nio storage mapping files

This is the answer to the specific questions about the basic knowledge of the Java Ipar O system. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report