1. Byte buffer stream
1.1 byte buffer stream construction method [application]
- Introduction to byte buffer stream
- IBufferOutputStream: this class implements buffering Output stream. It is not necessary to write bytes to the output stream of the underlying application through the call of the underlying system.
- Ibbufferedlnputstream: creating BufferedInputStream will create an internal buffer array. When bytes are read or skipped from the stream, the internal buffer will be refilled from the included input stream as needed, many bytes at a time
- Construction method
Method name |
explain |
BufferOutputStream(OutputStream out) |
Create byte buffered output stream object |
BufferedlnputStream(InputStream in) |
Create byte buffered input stream object |
public class BufferStreamDemo{
public sattic void main(String[] args) throws IOException {
//Byte buffered output stream: BufferedOutputStream(OutputStream out)
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("muByteStream\\bos.txt"));
//Write data
bos.write("hello\r\n".getBytes());
bos.write("world\r\n".getBytes());
//Release resources
bos.close();
//Byte buffered input stream: BufferedInputStream(InputStream in)
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("myByteStream\\bos.txt"));
//Read one byte of data at a time
int by;
while((by =bis.rea())!=-1) {
System.out.print((char)by);
}
//Read one byte array data at a time
byte[] bys = new byte[1024];
int len;
while ((len = bis.read())!=-1) {
System.out.print(new String(bys,o,len));
}
//Release resources
bis.close();
}
}
1.2 byte stream copy video [application]
- Case requirements
Copy "E: \ Java \ java.avi" to "java.avi" under the module directory
- Implementation steps
- Create byte stream input stream object from data source
- Create byte output stream object based on destination address
- Read and write data, copy video
- Release resources
- code implementation
public class CopyAviDemo {
public static void main(String[] args) throws IOException {
//Record start time
long startTime = System.currentTimeMillis();
//Copy video
method1();
method2();
method3();
method4();
//Record end time
long endTime = System.currentTimeMillis();
System.out.println("Total time:"+(endTime-StartTime)+"millisecond");
}
//The basic byte stream reads and writes one byte at a time
public static void method1 throws IOException {
//"E:\JAVASE\java.avi
//Java. Java under module directory avi
FileInputStream fis = new FileInputStream("E:\JAVASE\java.avi");
FileOutputStream fos = new FileOutputStream("mySbyteStream\\java.avi");
int by;
while((by = fis.read())!=-1){
fos.write(by);
}
fos.close();
fis.close();
}
//The basic byte stream reads and writes one byte array at a time
public static void method2 throws IOException {
//"E:\JAVASE\java.avi
//Java. Java under module directory avi
FileInputStream fis = new FileInputStream("E:\JAVASE\java.avi");
FileOutputStream fos = new FileOutputStream("mySbyteStream\\java.avi");
byte[] bys = new byte[1024];
int len;
while((len = fis.read(bys))!=-1){
fos.write(bys,0,len);
}
fos.close();
fis.close();
}
//The byte buffer stream reads and writes one byte at a time
public static void method3 throws IOException {
BufferedInputStream bis = new BufferedInputStream("E:\JAVASE\java.avi");
BufferedOutputStream bos = new BufferedOutputStream("mySbyteStream\\java.avi");
int by;
while((by = bis.read())!=-1){
bos.write(by);
}
bos.close();
bis.close();
}
//The byte buffer stream reads and writes one byte array at a time
public static void method3 throws IOException {
BufferedInputStream bis = new BufferedInputStream("E:\JAVASE\java.avi");
BufferedOutputStream bos = new BufferedOutputStream("mySbyteStream\\java.avi");
byte[] bys = new byte[1024];
int len;
while((len = bis.read(bys))!=-1){
bos.write(bys,0,len);
}
bos.close();
bis.close();
}
}
2. Character stream
2.1 why does character flow appear [understand]
2.2 coding table [ understanding ]
2.3 encoding and decoding problems in strings [application]
2.4 encoding and decoding problems in character stream [application]
2.5 five ways of writing data in character stream [application]
2.6 method of reading data from character stream [application]
2.7 character stream copying Java file [application]
2.8 character stream copying Java file improved version [application]
2.9 character buffer stream [application]
2.10 character buffer stream copying Java file [application]
2.11 special function of character buffer stream [application]
2.12 what is the special function of character buffer stream? Copy Java file [application]
2.13 IO flow summary [understanding]
- Byte stream
- Character stream
3. Practice cases
3.1 assemble to file [ application ]
3.2 file to collection [application]
3.3 roll call device [ application ]
3.4 collection to document improved version [application]
3.5 document collection improved version [application]