----------Android Training, Java training, Java Learning Technology blog, look forward to communicating with you! ------------ First,
I. Three ways to classify IO streams
1. Divided by Flow direction: input stream and output stream
2. Different data units by stream are divided into: byte stream and character stream
3. According to the function of the stream is divided into: node flow and processing flow
The four abstract classes of IO Flow:
Character Stream: Reader Writer
BYTE stream: InputStream (read data)
OutputStream (Write data)
Three, the basic method of InputStream
int read () throws IOException reads a byte returned as an integer, assuming that 1 is returned to the end of the input stream
void Close () throws IOException close stream frees memory resource
Long Skip (long N) throws IOException Skip N bytes Unread
Iv. Basic methods of OutputStream
void write (int b) throws IOException writes a byte of data to the output stream
void Flush () throws IOException writes the buffered data from the output stream to the destination
V. Basic methods of writer
void write (int c) throws IOException writes a character data to the output stream
void write (String str) throws IOException writes a character in a string to the output stream
void write (String str. int offset,int length)
Writes a string from the length of the offset beginning to the output stream
void Flush () throws IOException
Writes the buffered data from the output stream to the destination
Vi. Basic methods of reader
The code specifically explains:
System.in
int read () throws IOException reads a character returned as an integer. Assume that 1 is returned to the end of the input stream
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
/*
* System.in is inputstream static final, including polymorphic, called synchronous or plug-type
* Read ASCII and binary files (Pictures). The letters are ASCII characters (personal understanding).
*/
public class Testsystemin {
public static void Main (string[] args) {
InputStreamReader ISR = new InputStreamReader (system.in);
BufferedReader br = new BufferedReader (ISR);//Have ReadLine
String s = null;
try {
s = Br.readline ();
while (S!=null) {
if (S.equalsignorecase ("Exit")) {
Break
}
System.out.println (S.touppercase ());
s = Br.readline ();
}
Br.close ();
}catch (IOException e) {
E.printstacktrace ();
}
}
}
BA, FileInputStream
Import java.io.*;
public class Testfileinputstream {
public static void Main (string[] args) {
FileInputStream in = null;
try {
in = new FileInputStream ("E:/1.txt");
}catch (FileNotFoundException e) {
SYSTEM.OUT.PRINTLN ("File not Found");
System.exit (-1);
}
The following indicates that a file was found
int tag = 0;
try {
Long num = 0;
while ((tag = In.read ())!=-1) {
Read is a byte stream, if there is a Chinese character on the display is not normal, using reader to conquer the
System.out.print ((char) tag);
num++;
}
In.close ();
System.out.println ();
SYSTEM.OUT.PRINTLN ("total read" + num + "character");
}catch (IOException E1) {//read and close all throw IOException
SYSTEM.OUT.PRINTLN ("file read error");
System.exit (-1);
}
}
}
Black Horse Program Ape--java base--io Flow