The basic output stream class of Java is: Java. Io. outputstream:
public abstract class OutputStream
This class provides the basic methods required to write data. These methods include:
public abstract void write(int b) throws IOExceptionpublic void write(byte[] data) throws IOExceptionpublic void write(byte[] data,int offset,int length) throws IOExceptionpublic void flush() throws IOExceptionpublic void close() throws IOException
The subclass of outputstream uses these methods to write data to a specific media. For example, fileoutputstream writes data to a file using these methods. Telnetoutputstream uses these methods to write data to a network connection. Bytearrayoutputstream uses these methods to write data to an extended byte array. However, no matter which media is written, most of them use the same five methods.
The basic method of outputstream is write (int B ). This method takes an integer between 0 and 255 as the parameter and writes the corresponding bytes to the output stream. This method is declared as an abstract method, because each subclass needs to modify this method to process specific media. For example, bytearrayoutputstream can use pure Java code to copy bytes to the array. Different from this, fileoutputstream uses native code to learn how to write data to files on the host platform.
Note that although this method accepts an int as a parameter, it will actually write an unsigned byte. Java does not have an unsigned byte data type, so int should be used here. The only real difference between unsigned bytes and signed Bytes: They all consist of eight binary digits. When you write an int into a network connection using write (int B, only eight binary digits are placed on the cable. If a request exceeds 0 ~ 255 int passed into write (int B), will write the lowest number of bytes, the other three bytes will be ignored (this is the result of forcibly converting int to byte ). Tip: however, in rare cases, you may see some problematic third-party classes, which are written in excess of 0 ~ When the value is 255, their practices are different. For example, illegalargumentexception is thrown or 255 is always written, so try to avoid writing more than 0 ~ 255 Int.
To be continued ....................................
Stream output stream