-1

I want download only first 3 bytes of file from web, but can't do that.

This method download all file

BufferedReader r = new BufferedReader(new InputStreamReader(imageStream), 3);

as I get InputStream class always download all file..

2 Answers2

0

BufferedReaderis handy if you are trying to read characters. For example: char[] charBuff = new charBuff[n]; new BufferedReader(new InputStreamReader(stream)).read(charBuff,0,n); This Wii read n bytes from the input stream and will store them in the char array.

If you just want to read bytes and store them in a byte array try using this: byte[] byteBuff= new byteBuff[n]; new BufferedInputStream(input stream).read(byteBuff,0,n);

NewestStackOverflowUser
  • 2,792
  • 5
  • 22
  • 31
0
connection.setRequestProperty("Range", "bytes="+0+"-"+2);
        connection.connect();

        BufferedReader r = new BufferedReader(new InputStreamReader(connection.getInputStream()));

        StringBuilder total = new StringBuilder();
        String line;
        line = r.readLine();
        Log.i(LOG_TAG, line);