Created
July 14, 2020 17:06
-
-
Save anta40/55f92f6cdfbca95e0872af8216cf64af to your computer and use it in GitHub Desktop.
Load a file and return its Base 64 value
This file contains hidden or 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 String fileToBase64(String path){ | |
String base64 = ""; | |
try { | |
File file = new File(path); | |
byte[] buffer = new byte[(int) file.length() + 100]; | |
@SuppressWarnings("resource") | |
int length = new FileInputStream(file).read(buffer); | |
base64 = Base64.encodeToString(buffer, 0, length, Base64.DEFAULT); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return base64; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment