byte[]转为FileInputStream
时间: 2024-01-07 21:03:08 浏览: 296
Java使用FileInputStream流读取文件示例详解
byte[]可以通过将其写入一个临时文件来转换为FileInputStream。下面是一个示例代码,演示了如何将byte[]转换为FileInputStream:
```java
FileInputStream byteToFile(byte[] bytes, String fileName) {
File file = new File(fileName);
FileInputStream fileInputStream = null;
try {
OutputStream output = new FileOutputStream(file);
BufferedOutputStream bufferedOutput = new BufferedOutputStream(output);
bufferedOutput.write(bytes);
fileInputStream = new FileInputStream(file);
file.deleteOnExit();
return fileInputStream;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return fileInputStream;
}
```
阅读全文