視頻文件轉換為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);
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM