jdk6 中 如何将 Base64 转为 File 类

网上搜到的是将 Base64转为图片 并保存到某一盘符下,要么就是 jdk版本限制;
由于下游的数据处理是以 Blob 类型存储到数据库中的,
在上游只需将 Base64 转为 File类,但不用输出到某一盘符就可以了;
Stream 的转换很头大,希望大神可以指点一下,谢谢

    public void base64ToFile(String base64, String pdfName) {
        FileOutputStream fileOutputStream = null;
        try {
            //创建文件目录
            String filePath="D:\\image";
            File file=new File(filePath);
            if (!file.exists() && !file.isDirectory()) {
                file.mkdirs();
            }
            byte[] s = Base64.decodeBase64(base64.getBytes());
            fileOutputStream = new FileOutputStream(file+File.separator+pdfName);
            fileOutputStream.write(s);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

** 解决问题的方法有很多,当花费大量时间跟精力,还是未能解决问题的时候,可以换一种思路;**

闲下来的时候,给这个问题收一下尾;

这里采取了页面处理,参考了: JavaScript将base64图片转换成formData并通过AJAX提交

后台声明 File 类来接收

BASE64解码成File文件

public static void base64ToFile(String base64, String fileName) {
File file = null;
//创建文件目录
String filePath="D:\image";
File dir=new File(filePath);
if (!dir.exists() && !dir.isDirectory()) {
dir.mkdirs();
}
BufferedOutputStream bos = null;
java.io.FileOutputStream fos = null;
try {
byte[] bytes = Base64.getDecoder().decode(base64);
file=new File(filePath+"\"+fileName);
fos = new java.io.FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(bytes);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}