|
//下载附件,模仿http://doc.jsdroid.com/docs/library/library这里,把附近添加为库
import org.apache.commons.codec1.binary.Base64
//文字方式
String base64String = "whuang123";
byte[] result = Base64.encodeBase64(base64String.getBytes());
String s = new String(result);
print s
//文字方式
//图片方式
static String file2Base64(String filePath) {
FileInputStream objFileIS = null;
try {
objFileIS = new FileInputStream(filePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
byte[] byteBufferString = new byte[1024];
try {
for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1; ) {
objByteArrayOS.write(byteBufferString, 0, readNum);
}
} catch (IOException e) {
e.printStackTrace();
}
String videodata = Base64.encodeBase64String(objByteArrayOS.toByteArray())
return videodata;
}
print file2Base64("/sdcard/Pictures/123.jpg")
//图片方式 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|