On Dec 16, 2011, at 5:01 AM, [email protected] wrote:

>        in = assetManager.open("test.z8");
>        size = in.available();
>        buffer = new byte[size];
>        while ((len = in.read(buffer, 0, size)) != -1){
>               f.write(in.read());
>        }

Problem lies within your while -loop. First you try to read "size" amount of 
data but write only "in.read()" which returns exactly one byte. Using 
"f.write(buffer)" should fix your copy method. Anyway, in general it's usually 
safest not to rely on InputStream.available() to return actual amount of bytes 
it has to offer. Yet alone expect InputStream.read(buffer, 0, size) read 
exactly the amount of bytes you're asking for.

In your case;
InputStream is = assetManager.open("filename");
byte[] buffer = new byte[8192]; // Fixed size buffer
int len;
while ((len = is.read(buffer, 0, buffer.length)) != -1) {
    os.write(buffer, 0, len);
}

Might be more reliable solution.

--
H

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

Reply via email to