The basic operation of the data type stream

Data input stream: DataInputStream

DataInputStream(InputStream in)

Data output stream: DataOutputStream

DataOutputStream(OutputStream out)

Memory Operation Flow: means for temporarily storing the information processing program ends, data from memory disappear

Operation byte array

ByteArrayIntputStream

ByteArrayOutputStream

Operating array of characters

charArrayReader

charArrayWriter

String operations

StringReader

StringWriter

Print flow characteristics:

Only operate a destination, the data source can not operate

Any type of data can be operated

If you have activated the automatic refresh automatically refresh

You can stream (stream copy print a text file) file operations

flow:

Elementary streams: stream is directly read and write the file;

Advanced Stream: provides some additional capabilities to the base of the stream

Which stream object can directly manipulate text files it

FileInputStream

FileOutputStream

FileReader

FileWriter

PrintStream

PrintWriter

See the API, the stream object constructor check, if File Type parameter of type String and at the same time, in general, the operation is directly stream files

PrintWriter

1. can operate any type of data

print() println()

2. Enable auto-refresh

PrintWriter pw=new PrintWriter(new FileWriter("pw.txt",true));

Or should call the println method can

This time not only automatically refresh the data also achieved wrap

println () is equivalent to

bw.writer();

bw.newLine();

bw.flush();

Stdio stream

field in a class system: in, out

Each represents a system standard input and output devices

The default input device is a keyboard, an output device is a calculator

System.in type is InputStream

System.out PrintStream type is a subclass of a subclass of FilterOutputStream OutputStream

:( three kinds of keyboard input data)

arg receiving main method parameters General: A

java helloWorld hello world java

B: Scanner (JDK5 later)

Scanner sc=new Scanner(System.in);

String sc=sc.nextLine();

int x=sc.nextInt();

C: the character the buffer flow through the package to achieve the standard input stream

BufferedReader br=new BufferedReader(new InputStreamReader(System.in))

String line=br.readLine();

int i=Integar.parseInt(br.readLine());

Random access stream

RandomAccessFile Overview

RandomAccessFile class does not belong to the stream, is a subclass of the Object class, but it combines the InputStream and OutputStream functionality, support for random read and write access to the file

public RandomAccessFile(String name,String mode):

The first parameter is the path to the file, the second argument is the mode of operation of the document, there are four models, we most commonly called "rw", in this way means I can either read can also write data

Merge Flow:

SequenceInputStream Overview

SequenceInputStream class can stream a plurality of input streams together into one input stream, this stream is also referred to as a combined stream

SequenceInputStream constructor

SequenceInputStream(InputStream s1,InputStream s2)

sequenceInputStream(Enumeration<?extends InputStream> e)

The contents of multiple files written to a text file

Serialization stream:

The objects stored in a text file or streamed in accordance with the same transmission network

objectOnputStream objects --------------> data stream

Deserialized stream:

Object data stream to restore a text file into an object or the network

objectInputStream stream ----------> Object

Achieve serialization:

Note: exception is the sequence (NotSerializableException)

Classes implementing the java.io.Serializable interface enable sequence features, do not implement this interface state can not make any serialization and deserialization (actually there is no method of this interface, similar to the method of this subclass are not referred to marker interface)

We want to know is:

See class implements the serialization interface when trying to solve the problem of the yellow warning line, it can automatically generate a serialized ID value, and this value is generated later, we change any class that reads previous data There is no problem

Note: There may be a class member variables are many, some of us do not want to serialize, ask how to do it, using the transient keyword to declare member variables do not need to serialize

 

 

 

Guess you like

Origin blog.csdn.net/qq_40935960/article/details/94960175