public File getFile(byte[] bfile, String fileName) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
String path = "";
try {
File dir = new File(this.getClass().getResource("/").getPath());
if(!dir.exists()&&!dir.isDirectory()){
dir.mkdirs();
}
file = File.createTempFile(fileName, ".jpg", dir);
file.deleteOnExit();
String tempFileName = file.getName();
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(bfile);
path = file.getPath();
return file;
} catch (Exception e) {
e.printStackTrace();
System.out.println("创建临时文件失败!" + e.getMessage());
return null;
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}