Java (4) -- IO stream, java -- io stream

Source: Internet
Author: User

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 ();
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.