首页 > 其他分享 >音频和base64的转化实现

音频和base64的转化实现

时间:2022-11-01 17:13:50浏览次数:43  
标签:String buffer 音频 base64 转化 file new inputFile

1.语音文件路径转化为BASE64格式的String 源码

 public static String encodeBase64File(String path) throws Exception {
        File file = new File(path);;
        FileInputStream inputFile = new FileInputStream(file);
        byte[] buffer = new byte[(int) file.length()];
        inputFile.read(buffer);
        inputFile.close();
        return new BASE64Encoder().encode(buffer);
    }

2.将base64字符解码保存文件

/**
     * 将base64字符解码保存文件
     * @param base64Code
     * @param targetPath
     * @throws Exception
     */
    public static void decoderBase64File(String base64Code, String targetPath)
            throws Exception {
        byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);
        FileOutputStream out = new FileOutputStream(targetPath+"/1.wav");
        out.write(buffer);
        out.close();
    }

 

标签:String,buffer,音频,base64,转化,file,new,inputFile
From: https://www.cnblogs.com/slf784049656/p/16848347.html

相关文章