int byte1; String pageData = ""; ByteBuffer buf = ByteBuffer.allocateDirect(1024); InputStream in = uconn.getInputStream(); synchronized(buf) { while((byte1 = in.read()) >= 0) { try { buf.put((byte) byte1); } catch (BufferOverflowException e) { buf.flip(); byte[] bytes = new byte[buf.remaining()]; buf.get(bytes); pageData += new String(bytes); buf.clear(); buf.put((byte) byte1); } } buf.flip(); byte[] bytes = new byte[buf.remaining()]; buf.get(bytes); pageData += new String(bytes); buf.clear(); } System.out.println(pageData);