简体   繁体   English

ByteArrayOutputStream vs FileOutputStream从内存使用和性能的角度来看

[英]ByteArrayOutputStream vs FileOutputStream from memory usage and performance point of view

What I want to do is to download a file from the web server. 我想要做的是从Web服务器下载文件。 When I traced the code, two programmers uses ByteArrayOutputStream and FileOutputStream differently to download file in the same scenario. 当我跟踪代码时,两个程序员以不同的方式使用ByteArrayOutputStream和FileOutputStream来下载同一场景中的文件。 These are 这些是

  • Case 1 : use ByteArrayOutputStream to create a file and download it. 案例1 :使用ByteArrayOutputStream创建文件并下载。

  • Case 2 : use FileOutputStream to temporarily create a file under web server and download it and then delete this file. 案例2 :使用FileOutputStream在Web服务器下临时创建文件并下载然后删除该文件。

PS: Case 2 file is larger than case 1 file. PS:案例2文件大于案例1文件。

Can I use ByteArrayOutputStream to both cases? 我可以在两种情况下使用ByteArrayOutputStream吗? Is there any intention to use FileOutputStream in second case? 是否有意在第二种情况下使用FileOutputStream 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. 结合Boris The Spider和Peter Lawrey的回答: ByteArrayOutputStream在内存中, FileOutputStream是一个文件。 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. ByteArrayOutputStream更快但考虑下载一个10Gb文件......这似乎在程序中打开了一个很好的安全漏洞 - 只需要输入一个大文件。 Also ByteArrayOutputStream is limited to just under 2GB as it uses a byte[] ByteArrayOutputStream也限制在2GB以下,因为它使用了一个byte []

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FileOutputStream与ByteArrayOutputStream - FileOutputStream vs ByteArrayOutputStream 将ByteArrayOutputStream写入FileOutputStream vs将ByteArray写入FileOutputStream? - Write ByteArrayOutputStream to FileOutputStream vs Write ByteArray to FileOutputStream? ByteArrayOutputStream过度使用RAM内存 - Extream usage of RAM memory by ByteArrayOutputStream 性能:Java中的BufferedOutputStream与FileOutputStream - Performance : BufferedOutputStream vs FileOutputStream in Java 内存映射文件的性能/稳定性 - Native或MappedByteBuffer - 与普通的'FileOutputStream相比 - Performance / stability of a Memory Mapped file - Native or MappedByteBuffer - vs. plain ol' FileOutputStream ByteArrayOutputStream性能 - ByteArrayOutputStream performance EJB Vs WebService?绩效观点 - EJB Vs WebService? Performance point of view Java阵列与C ++阵列中的性能和内存使用情况 - Performance and memory usage in Java arrays vs C++ arrays Concat整数到字符串 - 从性能和内存的角度来看,使用字符串文字或原语? - Concat an integer to a String - use String literal or primitive from performance and memory point of view? 在性能方面,在什么时候用BufferedOutputStream包装FileOutputStream是有意义的? - At what point does wrapping a FileOutputStream with a BufferedOutputStream make sense, in terms of performance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM