import java.util.Base64; try { File imageFile = new File("path/to/image.png"); FileInputStream imageInFile = new FileInputStream(imageFile); byte[] imageData = new byte[(int) imageFile.length()]; imageInFile.read(imageData); String encodedImage = Base64.getEncoder().encodeToString(imageData); System.out.println("Encoded Image: " + encodedImage); imageInFile.close(); } catch (IOException e) { e.printStackTrace(); } try { byte[] decodedImage = Base64.getDecoder().decode(encodedImage); FileOutputStream imageOutFile = new FileOutputStream("path/to/newimage.png"); imageOutFile.write(decodedImage); imageOutFile.close(); } catch (IOException e) { e.printStackTrace(); }


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