读写文件的时候经常会碰到写的文件和读的文件不一样导致各种各样的问题,其实就是代码需要修改的问题:
记住先读后写,满足读到的条件才去写到byte数组去。
int len = 0;
InputStream is = new ByteArrayInputStream(pdfByteArray);
OutputStream os = null;
byte[] bytearray = new byte[1024];
try {
os = new FileOutputStream(PDFDir + PDFFileName);
while((len = is.read(bytearray))!=-1){
os.write(bytearray,0,len);
}
is.close();
os.close();
} catch (FileNotFoundException e1)
{ e1.printStackTrace(); }
catch (IOException e)
{ e.printStackTrace(); }
记住先读后写,满足读到的条件才去写到byte数组去。