java - FileOutputStream appending issue, where I am going wrong? -
i trying 3 5 pdf file(from internet source) & merging them 1 after another. fyi, dont want use itext or other pdf lib, because, please @ code once
public static void savefile(string[] urls, string filename) throws ioexception { clienturlconnection clienturlconnection = null; inputstream inputstream = null; try { int t = 1; fileoutputstream outputstream = new fileoutputstream(filename,true); (string url : urls) { clienturlconnection = new clienturlconnection(url); clienturlconnection.sethttpmethod(clienturlconnection.get_method); inputstream = clienturlconnection.getinputstream(); outputstream.write(ioutils.tobytearray(inputstream)); inputstream.close(); outputstream.flush(); system.out.println((t++) + " - file inserted in " + filename + "\n"); thread.sleep(3000); } outputstream.close(); } catch (exception ex) { ex.printstacktrace(); } }
string[] urls - array of url's pdf document. sting filename - single file store pdf's in it. clienturlconnecion - own class handle proxy , other things.
expected output - 2 pdf's urls in single file
actual output - second pdf overwriting first one, size of file sum of size of 2 pdf's.
problem - made fileoutputstream - append true, overwriting. don't understand i'm doing wrong
thanks in advance
merging 2 pdf files not equivalent appending binary content of files.
your code may append bytes way want -as suggests size of output file-, seems last appended file read pdf reader when open it.
therefore, probably should use api read actual content of pdf.
Comments
Post a Comment