Question

3
Replies
184
Views
THILANPEIRIS Member since 2012 3 posts
Evonsys
Posted: 2 months ago
Last activity: 4 weeks ago

How to convert a file into base64 string

How to convert a file into base64 string?

Please provide a sample java code.

Currently I'm trying to use below, but it does not return correct base64 string value.

 

java.io.File file = new java.io.File("D://Folder1//Folder2//Test.txt");  FileExists=file.exists(); //init array with file length byte[] bytesArray = new byte[(int) file.length()];

//encode the byte array into Base64. try {     //Base64String = Base64Util.encodeToString(bytesArray);   Base64String = java.util.Base64.getMimeEncoder().encodeToString(bytesArray);   } catch (Exception e) {       throw new PRRuntimeException("Can't attach the file to the Work Object");      }

 

***Edited by Moderator Marissa to update General to Product***  

Pega Platform Case Management Other Industry System Architect
Share this page LinkedIn