views:

32

answers:

1

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?)

+1  A: 

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.

BrennaSoft
@BrennaSoft, the content of the file is string (xml file). So I ended up doing new String( part.getBytes()).
portoalet