InputStream is = new ByteArrayInputStream(pdfByteArray); byte[] bytearray = new byte[1024]; try { OutputStream os = new FileOutputStream(PDFDir + PDFFileName); do{ is.read(bytearray, 0, 1024); os.write(bytearray); }while (is.available() > 0); is.close(); os.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
os.write(bytearray,0,len);
没有这个方法吧,int len = is.read(bytearray);
Equivalent to read(buffer, 0, buffer.length).public int read (byte[] buffer, int byteOffset, int byteCount)
Reads up to byteCount bytes from this stream and stores them in the byte array buffer starting at byteOffset. Returns the number of bytes actually read or -1 if the end of the stream has been reached.你应该是读多少,写多少。
你的代码里,把数据读到一个长度为1024的byte数组里。但这个数组不一定能够被填满。而你写的总是1024长度。所以你拷贝完的文件总会比原始文件稍微大一点点。