java 中 byte[]、File、InputStream 互相轉換


1、將File、FileInputStream 轉換為byte數組:

File file = new File("test.txt");

InputStream input = new FileInputStream(file);

byte[] byt = new byte[input.available()];

input.read(byt);

 

2、將byte數組轉換為InputStream:

byte[] byt = new byte[1024];

InputStream input = new ByteArrayInputStream(byt);

 

3、將byte數組轉換為File:

File file = new File('');

OutputStream output = new FileOutputStream(file);

BufferedOutputStream bufferedOutput = new BufferedOutputStream(output);

bufferedOutput.write(byt);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM