I’m writing a file uploader in Spring MVC and I am encoding a file into a Base64 string to send to a web service using:
org.apache.commons.codec.binary.Base64;
String encoded = Base64.encodeBase64String(uploadItem.getFileData().getBytes());
The web service will send the encoded string back to me and I want to know how to regenerate the file from the encoded string. I know you can do this:
byte[] decoded = Base64.decodeBase64(encoded);
but how do you change the byte array back into the file?
You could write the bytes to a file using
FileOutputStreamas in this example.