2015-08-21 9 views
8

में बाइटएरे बफर गायब है एंड्रॉइड एसडीके 22-> 23 org.apache.http.util.ByteArrayBuffer अपडेट करते समय अब ​​और नहीं है - क्या कोई प्रतिस्थापन है या यह एक बग है?एसडीके 23

+0

असल में, सभी HttpClient को हटा दिया गया था। – CommonsWare

उत्तर

5
जावाडोक से

:

इस वर्ग एपीआई स्तर में पदावनत किया गया था 22.

कृपया openConnection() बजाय का उपयोग करें। अधिक जानकारी के लिए कृपया इस webpage पर जाएं।

34

इस जवाब देर से एक सा हो सकता है लेकिन एक वैकल्पिक ByteArrayOutputStream साथ ByteArrayBufferको बदलने के लिए है और इस प्रकार बाइट्स की एक सरणी का उपयोग करें:

ByteArraybuffer साथ कोड का उदाहरण:

BufferedInputStream bis = new BufferedInputStream(is); 
    ByteArrayBuffer baf = new ByteArrayBuffer(50); 
    while ((current = bis.read()) != -1) { 
       baf.append((byte) current); 
    } 
    FileOutputStream fos = new FileOutputStream(file); 
    fos.write(buffer.toByteArray()); 

अब, के साथ उपयोग करके ByteArrayOutputStream:

 BufferedInputStream bis = new BufferedInputStream(is); 
    ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 
    //We create an array of bytes 
    byte[] data = new byte[50]; 
    int current = 0; 

    while((current = bis.read(data,0,data.length)) != -1){ 
      buffer.write(data,0,current); 
    } 

    FileOutputStream fos = new FileOutputStream(file); 
    fos.write(buffer.toByteArray()); 
    fos.close(); 

अच्छा, मुझे आशा है कि यह उपयोगी होगा।

+0

बहुत उपयोगी, धन्यवाद – med116

+0

ग्रेट समाधान, धन्यवाद ~ – KaKa

संबंधित मुद्दे