base64 转字符串
/**
* 图片转BASE64
*/
public void encoder() {
UploadFile file = getFile();
BASE64Encoder encoder = new BASE64Encoder();
byte[] imgBase = imageBase64(file.getFile());
String endcoderStr = encoder.encode(imgBase);
}
public byte[] imageBase64(File file) {
FileInputStream fis;
byte[] bytes = null;
try {
fis = new FileInputStream(file);
bytes = new byte[fis.available()];
fis.read(bytes);
} catch (Exception e) {
e.printStackTrace();
}
return bytes;
}
字符串转base64
/**
* 字符串转byte
*/
public void decoder(String endcoderStr) throws IOException {
BASE64Decoder decoder = new BASE64Decoder();
byte[] imgBase = decoder.decodeBuffer(endcoderStr);
}