The stream ending with stream is called a universal flow (byte stream), otherwise a character stream
Overview of 1.java streams:
A file is usually made up of a string of bytes or characters, and the sequence of bytes composing the file is called a byte stream, and the sequence of characters that make up the file is called a character stream.
In 2.Java, the direction of the flow can be divided into: input stream and output stream
Input stream: An input stream is the process of loading data from a file or other input device into memory
Output stream: The output stream is to save the in-memory data to a file or other input device
?????? 3. If the file is made up of bytes or characters, then loading the file into memory or outputting the file to a file requires support from both the input stream and the output stream, then the input and output streams are divided into two types in the Java language:
byte input stream, byte output stream character input stream, character output stream
3.1 InputStream (Byte input stream): InputStream is an abstract class, all implements the InputStream class is the byte input stream, the main understanding suddenly class can:
Example:
public class test{
public static void Main (string[] args) throws exception{
Create an input stream
InputStream in=new FileInputStream ("C:/a.txt");
Define a temporary variable
int temp=0;
while ((Temp=in.read ())!=-1) {
System.out.println ((char) temp);
}
}
}
3.2 outputstream (Byte output stream): OutputStream is an abstract class, all implementations of this class are byte output streams
If the close () method is called, the Flush () method is called automatically, but it is recommended to manually display the flush () method
Example:
public class Test {
public static void Main (string[] args) {
Create an output byte stream
OutputStream out = null;
try {
out = new FileOutputStream ("C:/b.txt");
Out.write (123);
Flush or close must be called
Out.flush ();
} catch (Exception e) {
E.printstacktrace ();
}finally {
try {
Out.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
SYSTEM.OUT.PRINTLN ("Success");
}
}
jdk1.8 new feature auto-close:
Example:
public class test{
public static void Main (string[] args) {
Try (Outputsreeam out =new fileoutputstream ("C:/c.txt");) {
Create an output byte stream
Out.write (1);
The flush method must be called
Out.flush ();
}catch (Exception e) {
E.printstacktrace ();
}
SYSTEM.OUT.PRINTLN (Success);
}
}
IO stream-----(byte stream)