No, this is a bad idea. This consumes memory -- and for large files, it can consume more memory than you have.
It is also completely unnecessary. The loop to do repeat over the buffer is just 3 lines of code, including the final '}'. That's actually easier than figuring out how big to make the buffer, and allocating it -- and for many types of streams, it is impossible to find how big to make the buffer. Please look at my earlier message on the topic, and memorize that pattern. Once you understand it, it's not hard to just do it when needed -- and you'll find you need it often. On Monday, May 2, 2011 12:51:36 AM UTC-7, Daniel Felix wrote: > > Hi, > > You should set a buffet size of file and then read it all in one > time in that buffer. It will solved your problem. > Once I was stuck such kind of problem and I tried different ways > and finally I used NDK for it but my problem > was not same I was trying to read a file from the server and have > no idea what is the exact size of the file. > The simple solution is buffer size of file type and read whole file > in one time. > > Yours, > > > On Apr 28, 6:29 pm, Hitendrasinh Gohil <[email protected]> > wrote: > > hi, > > > > Below is my code that i am writing the file. > > > > FileOutputStream fileOutput = new FileOutputStream(filepath); > > > > InputStream inputStream = urlConnection.getInputStream(); > > > > int[] key = {123,456}; > > > int totalRead = 0; > > > int read = 0; > > > > > do > > > { > > > read = inputStream.read(buffer); > > > > > fileOutput.write(read ^ key[totalRead % > (key.length-1)]); > > > > > totalRead+=read; > > //totalRead++; > > > > > }while (read>0); > > > > i am able to write only some kbs from the inputstream. > > > > If i write the file byte by byte than it works but it takes to much > > time. > > like > > read= inputStream.read(); > > totalRead++; > > > > can anyone help me what is the problem with above code? > > > > regards, > > hitendrasinh gohil > > -- 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

