Package test; import java. io. bufferedInputStream; import java. io. bufferedOutputStream; import java. io. fileInputStream; import java. io. fileOutputStream; import java. io. IOException; import java. io. inputStream; import java. io. outputStream; class MyBufferedInputStream {private InputStream in; private byte buf [] = new byte [1000]; private int pos = 0; private int count = 0; MyBufferedInputStream (InputStream in) {this. In = in;} public int myRead () throws IOException {if (count = 0) {count = in. read (buf); if (count <0) return-1; pos = 0; byte B = buf [pos]; count --; pos ++; return B & 0xff ;} else if (count> 0) {byte B = buf [pos]; count --; pos ++; return B & 0xff;/* because B is of the byte type, java will automatically upgrade the returned value to int. Therefore, to ensure that-1 is not returned, perform operations on B and 0xff. That is, when the value of B is-1, the binary representation is 11111111 byte -- "int 11111111 --" 11111111 11111111 11111111 11111111 and 0xff ". --" 00000000 00000000 00000000 11111111 */} elsereturn-1 ;} public void myClose () throws IOException {in. close () ;}} public class MyBufferedInputStreamDemo {public static void main (String args []) throws IOException {long start = System. currentTimeMillis (); copy (); long end = System. currentTimeMillis (); System. out. print Ln (end-start) + "millisecond");} public static void copy () throws IOException {MyBufferedInputStream buf_= new MyBufferedInputStream (new FileInputStream ("D: \ My Documents ents \ My Pictures \ unnamed .jpg "); BufferedOutputStream bufos = new BufferedOutputStream (new FileOutputStream (" D: \ My Documents ents \ My Pictures \ test.jpg "); int by = 0; while (by = bufcm. myRead ())! =-1) {bufos. write (by); // The byte value is forcibly converted to the int value to remove the three and eight bits produced by the previous computation .} Bufos. close (); bufcm. myClose ();}}