![](/img/trans.png)
[英]base64 encode audio file and send as a String then decode the String
[英]How to Get an Audio File and decode to a base64 String?
我需要從SD卡中獲取音頻文件(我有路徑),但是如何轉換為base64並將其放入字符串中。 我需要它傳遞給Web服務。
嘗試這個
private void doFileUpload(){
byte[] videoBytes;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File(selectedPath));
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
baos.write(buf, 0, n);
String videoBytes = baos.toByteArray();
video_str = Base64.encodeBytes(videoBytes);
System.out.println("video array"+video_str);
} catch (Exception e) {
// TODO: handle exception
}}
並從org.apache.ws.commons.util.Base64或http://iharder.net/base64下載Base64類
使用apache ws-commons-utils中的org.apache.ws.commons.util.Base64類
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.