简体   繁体   中英

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

I wanted to know about the difference between these two block of lines of codes.

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

and

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

any advantage and disadvantage for either of them is welcome to clear out detail. Thanks in Advance.

FileTransfer has multiple constructors which expect different parameters.

Your first example calls the constructor which takes the content as a byte array ( byte[] ).

Your second example calls the constructor which takes an InputStream and will read the content itself from the passed InputStream .

If your file is big, obviously don't use the first one because it requires the whole file to be read into the memory.

The second approach seems better in all cases except if you also need the file content, then you would have to read it twice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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