byte[],File和InputStream的相互轉換

File、FileInputStream 轉換爲byte[]spa

File file = new File("test.txt");
InputStream input = new FileInputStream(file);
byte[] bytes = new byte[input.available()];
input.read(bytes);

byte[]轉換爲InputStreamcode

byte[] bytes = new byte[1024];
InputStream input = new ByteArrayInputStream(bytes);

byte[]轉換爲Fileblog

File file = new File("");
OutputStream os = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(bytes);
相關文章
相關標籤/搜索