视频文件转换为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);
    }

 

posted @ 2020-03-12 19:48  活出自己范儿  Views(5610)  Comments(0Edit  收藏  举报