zoukankan      html  css  js  c++  java
  • 视频文件转换为base64字符串

    1、视频文件转换为base64

     /**
         * 
         * @param videofilePath 视频文件路径带文件名
         * @return base64
         */
        public static String videoToBase64(File videofilePath) {
            long size = videofilePath.length();
            byte[] imageByte = new byte[(int) size];
            FileInputStream fs = null;
            BufferedInputStream bis = null;
            try {
                fs = new FileInputStream(videofilePath);
                bis = new BufferedInputStream(fs);
                bis.read(imageByte);
            } catch (FileNotFoundException e) {
                log.info("文件" + videofilePath.getName() + "不能被找到:{}", e.getMessage());
            } catch (IOException e) {
                log.info("byte转换BASE64出错:" + e.getMessage());
            } finally {
                if (bis != null) {
                    try {
                        bis.close();
                    } catch (IOException e) {
                        log.info("关闭输入流出错:" + e.getMessage());
                    }
                }
                if (fs != null) {
                    try {
                        fs.close();
                    } catch (IOException e) {
                        log.info("关闭输入流出错:" + e.getMessage());
                    }
                }
            }
            return (new sun.misc.BASE64Encoder()).encode(imageByte);
        }
    
    缘于生活,而归于工作。本人所书,而意于分享。 如有转载,请注明出处! --活出自己范儿
  • 相关阅读:
    记一次渗透测试(5)
    记一次渗透实战(一)
    Spring IOC/DI
    Mysql 索引
    Mysql 存储过程
    Mysql 视图
    Mysql 用户和权限
    Mysql 事务
    Mysql 常用函数
    Mysql 子查询
  • 原文地址:https://www.cnblogs.com/Small-sunshine/p/12482234.html
Copyright © 2011-2022 走看看