JAVA中 byte[]数组如何转为InputStream

来源:互联网 发布:it工作者 编辑:程序博客网 时间:2024/05/29 17:39

1、将File、FileInputStream 转换为byte[]数组:
File file = new File("file.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);

1 0