What I want to do is to download a file from the web server. When I traced the code, two programmers uses ByteArrayOutputStream and FileOutputStream differently to download file in the same scenario. These are
Case 1: use ByteArrayOutputStream
to create a file and download it.
Case 2: use FileOutputStream
to temporarily create a file under web server and download it and then delete this file.
PS: Case 2 file is larger than case 1 file.
Can I use ByteArrayOutputStream
to both cases? Is there any intention to use FileOutputStream
in second case? What I want to know is from performance and memory point of view. Thanks in advance.
Combining Boris The Spider's and Peter Lawrey's to an answer:
ByteArrayOutputStream
is in memory and FileOutputStream
is a file. The implications are obvious. ByteArrayOutputStream
is faster but consider downloading a 10Gb file... This would seem to open a nice security hole in the program - just feed it a large file.
Also ByteArrayOutputStream
is limited to just under 2GB as it uses a byte[]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With