我有一個可以像ZIP任何東西文件,RAR,TXT,CSV,DOC等。我想從它創建一個ByteArrayInputStream的。
我用它來上傳文件通過從阿帕奇百科全書網FTP FTPClient。如何從Java中的文件創建ByteArrayInputStream?
是否有人知道該怎麼辦呢?
例如:
String data = "hdfhdfhdfhd";
ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
我的代碼:
public static ByteArrayInputStream retrieveByteArrayInputStream(File file) {
ByteArrayInputStream in;
return in;
}
對於文件讀出在我使用的RandomAccessFile和整個文件的字節首先轉移到一個字節數組字節。我發現這是以字節讀取文件的非常快速的方式。 –
你爲什麼需要這樣做?您可以通過將FileInputStream複製到ByteArrayOutputStream,然後從中創建ByteArrayInputStream來完成此操作。它當然沒有意義。 –
請解釋你的用例。你可能只是想要一個FileInputStream。一旦擁有它,你打算如何使用它? –