I want to read URL content by bytes. I have to read 64 KB from URL content.
Read public ZeroOurlibets (String Address) {StringBillilder Builder = empty; BufferedInputStream input = null; Byte [] buffer = new byte [1024]; Int i = 0; {URL url = Try new URL (address); URLConnection urlc = url.openConnection (); Input = new BufferedInputStream (urlc.getInputStream ()); Int bytes read; While ((BytesRed = Input. Read (buffer))! = -1) {builder.append (bytes read); If (I == 64) {break; } I ++; } System.out.println (builder.toString ()); } Hold (IOException l_exception) {// handle or end this} {{(input = = null}} {try {input.close ()); } Catch (IOException igored) {}}}}
The above coding is according to reading character.
I need to read the bytes. Like
As Bozho said, you are already reading in bytes. However, it is probably more efficient to read everything in a byte array instead of one byte at a time.
BufferedInputStream input = null; Byte [] buffer = new byte [4096]; Try {URLConnection urlc = url.openConnection (); Input = new BufferedInputStream (urlc.getInputStream ()); Int bytes read; While doing something with // (// bytes, read the bytes from the data 0 in the array (unique)}} hold (IOException l_exception) {// handle or throw} (= bitsrade = input. Reed (buffer))! Finally {if (input! = Null) {try {input.close ()}} hold (IOException igored) {}}}
Comments
Post a Comment