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.