SharedByteArrayInputStream stream = (SharedByteArrayInputStream) content; ByteArrayOutputStream bOut = new ByteArrayOutputStream(); //Reading in chunks is better performance-wise than reading one byte at once. int r; byte[] buffer = new byte[32 * 1000]; //Read and write into the ByteArrayOutputStream while((r = stream.read(buffer) != -1){ bOut.write(buffer, 0, r); } String aloha = new String(bOut.toByteArray(), Charset.forName( "ISO-8859-1" )); writer.append(aloha+"\n"); stream.close();
FileOutputStream fileOutputStream = new FileOutputStream(filepath); SharedByteArrayInputStream stream = (SharedByteArrayInputStream) content; byte bite = 0; byte[] buffer = new byte[1024]; //here we're reading more than one byte at a time. while((bite=(byte) stream.read(buffer))!=-1){ //write to file output stream instead. fileOutputStream.write(buffer,0,bite); //don't append new line character. } stream.close(); //close the output stream if you're done. fileOutputStream.close();