import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Base64; public class Base64Encoder { public static void main(String[] args) throws Exception { String imagePath = "path/to/image.jpg"; Path path = Paths.get(imagePath); byte[] imageBytes = Files.readAllBytes(path); String encodedImage = Base64.getEncoder().encodeToString(imageBytes); System.out.println(encodedImage); } } import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Base64; public class Base64Decoder { public static void main(String[] args) throws Exception { String encodedImage = "base64-encoded-string"; byte[] decodedBytes = Base64.getDecoder().decode(encodedImage); Path path = Paths.get("path/to/decoded_image.jpg"); Files.write(path, decodedBytes); System.out.println("Image decoded and saved successfully!"); } }


上一篇:
下一篇:
切换中文