[英]The difference between InputStream and InputStreamReader when reading multi-byte characters
[英]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.