public static void main(String[] args) {
HashMap<String, Object> map = new HashMap<>();
map.put("a", "a");
map.put("b", "ab");
map.put("c", "ac");
try(FileWriter w = new FileWriter("d:/show.docx")) {
map.put("test", getImageBase("C:/Users/lenovo/Pictures/2737b15e1a594866885109e31e15b4e4.jpg"));
new ReadFreemarkerTemplate().createFile(map, w);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getImageBase(String src) throws Exception {
File file = new File(src);
if (!file.exists()) {
return "";
}
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(file);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (Exception e) {
// TODO: handle exception
}
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
}
图片转64进制
最新推荐文章于 2024-05-31 09:05:13 发布