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