Created
April 6, 2022 03:35
-
-
Save guozi/f7a229c418671cc55d90172639ef3d54 to your computer and use it in GitHub Desktop.
Image to Base64 String Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Convert { | |
public static void main(String[] args) { | |
// Convert Image File to Base64 String | |
byte[] fileContent = FileUtils.readFileToByteArray(new File(filePath)); | |
String encodedString = Base64.getEncoder().encodeToString(fileContent); | |
// Convert Base64 String to Image File | |
byte[] decodedBytes = Base64.getDecoder().decode(encodedString); | |
FileUtils.writeByteArrayToFile(new File(outputFileName), decodedBytes); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>commons-io</groupId> | |
<artifactId>commons-io</artifactId> | |
<version>2.11.0</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment