IO flow
Concept:
IO stream is used to process data transmission between devices
Java operates on data through streaming
Java classes for operation flow are in the IO package
Flow is divided into two kinds according to flow direction: input flow and output flow.
Flow can be divided into two types according to the type of flow operation:
Byte streams: Byte streams can manipulate any data because any data in a computer is stored in bytes
Character Stream: Character Stream can only operate pure character data, which is more convenient.
Commonly used parent classes for IO streams:
Abstract parent class of byte stream
InputStream
OutputStream
The abstract method of character class:
Reader
Writer
IO Programming
Import the classes in the IO package before use
IO exception handling when used
Release resources after use
InputStream
caseimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class demo1_FileInputStraem { public static void main(String[] args) throws IOException { //demo1(); FileInputStream fis =new FileInputStream("xxx.txt"); int a; while ((a=fis.read()) !=-1) { System.out.println(a); } fis.close(); } public static void demo1() throws FileNotFoundException, IOException { FileInputStream fis =new FileInputStream("xxx.txt");//Create stream objects int x=fis.read(); //Read a byte from the hard disk System.out.println(x); int y=fis.read(); System.out.println(y); int z=fis.read(); System.out.println(z); int c=fis.read(); System.out.println(c); fis.close(); //Turn off and release resources } }