Java.io.ByteArrayInputStream.skip() 方法


Java.io.ByteArrayInputStream.skip() 方法

package com.codingdict;



import java.io.ByteArrayInputStream;

import java.io.IOException;



public class ByteArrayInputStreamDemo {



   public static void main(String[] args) throws IOException {

      byte[] buf = {65, 66, 67, 68, 69};

      ByteArrayInputStream bais = null;



      try {



         // create new byte array input stream

         bais = new ByteArrayInputStream(buf);



         int value = 0;



         // read till the end of the stream

         while((value = bais.read())!=-1) {



            // skip single byte

            bais.skip(1);

            System.out.println(value);

         }



      } catch(Exception e) {



         // if I/O error occurs

         e.printStackTrace();

      } finally {

         if(bais!=null)

            bais.close();

      }   

   }

}