ArticleDirectory
- Bytearrayinputstream and bytearrayoutputstream
Bytearrayinputstream and bytearrayoutputstream
TheProgramThe output and input are both from the file. Of course, you can also set the output position on the memory. In this case, you must use bytearrayinputstream and bytearrayoutputstream to complete the input and output functions.
The main function of bytearrayinputstream is to input content into the memory.
The main function of bytearrayoutputstream is to output data in the memory.
In this case, the memory should be used as the Operation Point.
Bytearrayinputstream class definition:
Public class bytearrayinputstream extends inputstream
Constructor:
Public bytearrayinputstream (byte [] BUF)
Accept a byte array. In fact, the input to the memory is to pass data into the memory in the constructor.
Bytearrayoutputstream: the output is to write data from the memory.
Public void write (int B)
The following is a case-insensitive Conversion Program completed by the memory operation stream:
1 Import Java. Io. bytearrayinputstream;
2 Import Java. Io. bytearrayoutputstream;
3 Import Java. Io. ioexception;
4 Import Java. Io. inputstream;
5 Import Java. Io. outputstream;
6
7 Public Class Test22 {
8 Public Static Void Main (string [] ARGs) Throws Ioexception {
9 String STR = "Hello world !!! ";
10 Inputstream input = New Bytearrayinputstream (Str. getbytes ());
11 Outputstream output = New Bytearrayoutputstream ();
12 Int Temp = 0;
13 While (Temp = input. Read ())! =-1 ){
14 Output. Write (character. tolowercase (temp ));
15 }
16 Input. Close ();
17 Output. Close ();
18 System. Out. println (output. tostring ());
19 }
20 }