package com.ruoyi.wisdomarbitrate.utils; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Base64; public class ImageToBase64Converter { public static String imageToBase64(String imagePath) throws Exception { Path path = Paths.get(imagePath); byte[] imageBytes = Files.readAllBytes(path); String base64Image = Base64.getEncoder().encodeToString(imageBytes); return base64Image; } public static void main(String[] args) { String imagePath = "D:\\develop\\2.jpg"; try { String base64Image = imageToBase64(imagePath); System.out.println(base64Image); } catch (Exception e) { e.printStackTrace(); } } }