Java⽂件byte[]类型转File package com.biubiu.utils;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Utils {
/**
* ⽂件byte[]类型转File
*
* @param bytes bytes
* @param outPath 输出⽬录
* @param fileName ⽂件名
* @return
*/
public static File bytesToFile(byte[] bytes, String outPath, String fileName) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
File dir = new File(outPath);
if (!ists() && dir.isDirectory()) { //判断⽂件⽬录是否存在
dir.mkdirs();
}
file = new File(outPath + File.separator + fileName);
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(bytes);
} catch (Exception e) {
e.printStackTrace();
} finally {
java streamif (bos != null) {
try {
bos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return file;
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论