文件类型之间转换

2018-11-29 52 words 1 min read

File、FileInputStream、byte三种类型之间转换

1. 将FileFileInputStream 转换为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);

致谢

感谢您花时间阅读,谢谢。


author

Authored By WUHAOTIAN

A gentleman should always strive to improve himself

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it