Question
Areteans
AU
Last activity: 29 Sep 2020 5:28 EDT
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***