cannot download all the characters from a url in android -
i have download json file , store text file in application. using following code:
public void readandstorefile() throws exception { try { url url = new url(address); urlconnection con = url.openconnection(); int length = con.getcontentlength(); if (length > 0) { log.i("lenght of bytes received", "" + length); inputstream fis = con.getinputstream(); inputstreamreader isr = new inputstreamreader(fis); bufferedreader bf = new bufferedreader(isr); string content = new string(); string line = null; while ((line = bf.readline()) != null) { content += line; } fileoutputstream fos = c.openfileoutput(filename, context.mode_private); bufferedwriter bfw = new bufferedwriter(new outputstreamwriter( fos)); bfw.write(content); } else throw new negativearraysizeexception(); } catch (exception e) { throw e; } }
but reason whole json file not being downloaded text file. number of characters downloaded , written after downloading , writing stops. why happening?
the url using http://opisop.webuildapps.com/api/shops.json
thank in advance.
ok, found out answer , because of 8k buffer capacity 8192 bytes being read. stripped out buffers , went reading bytes using inputstreamreader , worked out fine.
Comments
Post a Comment