栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java将Base64转为图片/视频

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java将Base64转为图片/视频

1. base64转图片
 
    public static File base64ToImg(String base64,String targetPath){
        if (base64 == null || "".equals(base64)){
             return null;
        }
        File file = null;
        FileOutputStream fops = null;
        base64 = base64.replace("data:image/jpeg;base64,","");
        byte[] buff = DatatypeConverter.parsebase64Binary(base64);
        try {
            file = File.createTempFile("图片",".jpeg",new File(targetPath));
            fops = new FileOutputStream(file);
            fops.write(buff);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("--------------------------------"+"图片转换完成"+"--------------------------------");
        return file;
    }
2. base64转视频
 
    public static void base64ToVideo(String base64, String targetPath) {
        try {
            //base解密
            byte[] videoByte = new sun.misc.base64Decoder().decodeBuffer(base64);
            File videoFile = new File(videoFilePath);
            //输入视频文件
            FileOutputStream fos = new FileOutputStream(videoFile);
            fos.write(videoByte, 0, videoByte.length);
            fos.flush();
            fos.close();
        } catch (IOException e) {
            System.out.println("base64转换为视频异常");
        }
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/602641.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号