/**
* 字节转FileInputStream
*
* @param bytes
* @return
*/
public 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;
}
2018/08/30
注:从服务器下载文件,获得byte[],要上传到另一个服务器上,在字节转FileInputStream过程中,文件被写在了tomcat某个目录下,调用file.deleteOnExit()并没有把文件删除