[android-developers] Re: How to get an interval of bytes from a file?

2011-09-16 Thread Jens
Try java.io.RandomAccessFile.

Call RandomAccessFile#seek() to position the file pointer correctly
and then call one or more of the read(..) methods available in the
RandomAccessFile class. Or you could go balls deep and use a
FileChannel, but that is about as fun as pleasuring yourself with a
cheese-grater.

Oh, and RandomAccessFile#close it afterwards whydoncha.

On Sep 16, 4:04 pm, Lidia lidyp...@yahoo.com wrote:
 Hello, please help me,

 I have to upload different media files, some of them a big, and i have
 the possibility to upload a file in few pieces of encoded string of
 bytes.

 I need to read a particular interval of bytes from a file.
 I can't create an array of bytes from the whole file, because the
 application crashes, heap memory is too low, OutOfMemoryError happens.

 As i see the following is not what i need:

 byte[] output = new byte[(int) bytesToRead];
 InputStream is = new FileInputStream(file);
 is.read(output, offset, bytesToRead);

 Thanks in advance
 Lidia

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to get an interval of bytes from a file?

2011-09-16 Thread Lidia
Thanks Jens,

I already found a simple solution, to use skip() method:

InputStream is = new FileInputStream(file);
byte[] output = new byte[(int) bytesToRead];
is.skip(startPosition);
is.read(output, 0, bytesToRead);

and it seems to work good.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en