// Custom Buffer
Import java. Io .*;
Class mybufferedinputstream
{
Private byte [] Buf = new byte [1, 1024];
Private inputstream in;
Private int Pos = 0, Count = 0;
Mybufferedinputstream (inputstream in ){
This. In = in;
}
/*
Read one byte at a time from the buffer byte array.
*/
Public int myread (){
// Read hard disk data through the in object and store the data in Buf
If (COUNT = 0 ){
Count = in. Read (BUF );
If (count <0)
Return-1;
Pos = 0;
Byte B = Buf [POS];
Count --;
Pos ++;
Return B;
} Else if (count> 0 ){
Byte B = Buf [POS];
Count --;
Pos ++;
Return B;
}
Return-1;
}
Public void myclose (){
In. Close ();
}
}
Call Buffer:
Import Java. io. *; Class copymp3 {public static void main (string [] ARGs) throws exception {long start = system. currenttimemillis (); copy_1 (); long end = system. currenttimemillis (); system. out. println (end-Start);} // copy public static void copy_2 () throws exception {bufferedinputstream bufd = new bufferedinputstream (New fileinputstream ("C: \ 1.mp3 "); bufferedoutputstream bufos = new buff Eredoutputstream (New fileoutputstream ("C: \ 2.mp3"); int by = 0; while (by = bufcm. myread ())! =-1) {bufos. Write (by);} bufos. Close (); bufcm. myclose ();}}
-----------------------
Problem:
The copied file contains 0 bytes.
0000-0001
1111-1110
1111-1111
Byte:-1 ---> INT:-1
He will add 1 to the front. In order to add 0 to the front, & 255 is required.
Minimum four places & 15
1 1 1 1
Minimum 8 bits & 255
1111 1111