繁体   English   中英

字节[]和FileTranfer(DWR)中的InputStream之间的区别

[英]Difference between Byte[] and InputStream in FileTranfer (DWR)

我想知道这两行代码块之间的区别。

 byte[] fileBytes = FileUtils.readFileToByteArray(new File(completeFilePath.toString()));
  ..
 return new FileTransfer(errorFileName, "application/vnd.ms-excel", is);

 File csvFile = new File(completeFilePath.toString());
 InputStream is = new BufferedInputStream(new FileInputStream(csvFile));
 return new FileTransfer(errorFileName, "application/vnd.ms-excel", is);

我们欢迎您清除其中任何一个的优缺点。 提前致谢。

FileTransfer具有多个构造函数,它们期望使用不同的参数。

第一个示例调用构造函数,该构造函数将内容作为字节数组( byte[] )。

您的第二个示例调用构造函数,该构造函数接受一个InputStream并将从传递的InputStream读取内容本身。

如果文件很大,则显然不要使用第一个文件,因为它需要将整个文件读入内存。

在所有情况下,第二种方法似乎都更好,除非您还需要文件内容,则必须将其读取两次。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM