java图片转base64(不换行)

public static String ImageToBase64(String imgPath) {
  InputStream in = null;
  byte[] data = null;
  // 读取图片字节数组
  try {
  in = new FileInputStream(imgPath);
  data = new byte[in.available()];
  in.read(data);
  in.close();
  } catch (IOException e) {
  e.printStackTrace();
  }
String base64String = Base64.encodeBase64String(data);
System.out.println(base64String);
posted @ 2023-10-18 10:12  花田007  阅读(205)  评论(0编辑  收藏  举报