获取MultipartFile的内容

发布于 2024-09-08 16:23:53 字数 305 浏览 5 评论 0原文

我试图获取 MultipartFile 的内容,它是通过 MultipartHttpServletRequest.getFile() 获得的。

MultipartFile中有2个函数:

  • bytes[] getBytes() ()

  • InputStream getInputStream()

获取内容最有效的方法是什么? (你会使用哪种方法?)

I am trying to get the content of MultipartFile, which is obtained through MultipartHttpServletRequest.getFile().

There are 2 functions in MultipartFile:

  • bytes[] getBytes() ()

  • InputStream getInputStream()

What is the most efficient way to get the content? (Which method would you use?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2024-09-15 16:23:53

唯一的区别是,使用 getBytes() 时,数据已经从流中读取,而使用 getInputStream() 时,您仍然需要读取数据。

您使用什么取决于您想要对内容执行什么操作。如果您只想将其写入磁盘的图像,那么 getBytes() 会是最好的,但如果您想解析并执行某些操作的文本,那么 getInputStream() 可能会更好。

Only difference is that with getBytes() the data has already been read from the stream, whereas with getInputStream() you will still have to read the data.

What you use depends on what you want to do with the content. If its an image that you just want to write out to disk, then getBytes() would be best, but if it is Text that you want to parse and do something with, then getInputStream() might be better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文