zoukankan      html  css  js  c++  java
  • Java IO: ByteArrayInputStream

     

     

    The ByteArrayInputStream class of the Java IO API allows you to read data from byte arrays as streams. Here is a simple example:

    byte[] bytes = ... //get byte array from somewhere.
    
    InputStream input = new ByteArrayInputStream(bytes);
    
    int data = input.read();
    while(data != -1) {
      //do something with data
    
      data = input.read();
    }
    input.close();    
    

      

    ByteArrayInputStream's can be handy if your data is stored in an array, but you have a component that can only process it as an InputStream. The ByteArrayInputStream can thus wrap the byte array, and turn it into a stream.

    Note: The proper exception handling has been skipped here for the sake of clarity. To learn more about correct exception handling, go to Java IO Exception Handling.

  • 相关阅读:
    rockGenmel stone.txt
    WHICHDAY.txt
    WORKDAYS.txt
    WAIT_YN.txt
    WEEKDAYS.txt
    WHEREXY.txt
    KeySelected.txt
    WINDOW.txt
    UPPER.txt
    ParentShapes It.txt
  • 原文地址:https://www.cnblogs.com/hephec/p/4735462.html
Copyright © 2011-2022 走看看