1.file转换为base64 字符串
@Value("${file.store.path}\\")
private String path;
/**
* 将文件进行base64编码
* @param file
* @return
*/
public String FileToBase64(File file){
String base64 = null;
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(file);
data = new byte[in.available()];
in.read(data);
in.close();
System.out.println(base64);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BASE64Encoder encoder = new BASE64Encoder();
String result=encoder.encode(data);
return result;
}
</