Java (4) -- IO stream, java -- io stream
(1) Java Stream Input/Output Principle:
In a Java program, input/output operations on data are performed in the stream mode to obtain different types of data. The program inputs or outputs data through standard methods.
(2) java. io abstract stream classification:
Node stream and processing stream:
The node stream can read and write data (files, memory) from a specific data source (node)
The processing stream is connected to an existing stream (node stream or processing stream). It provides more powerful read/write functions for the program through data processing.
The basic method of IO stream:
Node stream: write or read
Processing stream: converting data types
Overview:
(3) summary:
Is a beginner, so there are incomplete summary. When learning this course, you must have full imagination and imagine various channels to input and output data. This part will be learned later. When it comes to learning, I will make up this part later! Please kindly advise!
Java IO stream
Step 1: Read the file row by row using IO streams;
Part 2: Add a row number before each row and a new row of data;
Part 3: Splice each new line of data as the content of the new text file;
Part 4: write the new internal volume into hello.txt
Step 5: Score
IO stream in JAVA
Import java. io .*;
Public class TestFileWriter {
Public static void main (String [] args ){
FileReader fr = null;
FileWriter fw = null;
Int B = 0;
Char [] cbuf = new char [18];
Try {
Fr = new FileReader ("E: \ java \ io \ a.txt ");
Fw = new FileWriter ("E: \ java \ io \ B .txt ");
While (B = fr. read (cbuf, 0, 18 ))! =-1 ){
Fw. write (cbuf, 0, 18 );
}
}
Catch (FileNotFoundException e ){
E. printStackTrace ();
}
Catch (IOException e ){
E. printStackTrace ();
}
Finally {
Try {
Fr. close ();
Fw. close ();
} Catch (IOException e ){
E. printStackTrace ();
}
}
}
}