Search code examples
javaimagefilebase64ico

create ico file from base64 string in Java


I get this ico base64 representation string (example, cut in the middle):

"data:image/x-icon;base64,AAABAAkAAAAAAAEAIADXwgAAlgAAAI...AAA=".

How do i create ico file from it in Java?

Edit: it didn't work with Files.write


Solution

  • In previous projects, I did the following:

    byte[] data = Base64.decodeBase64(base64string);
    try {
        OutputStream stream = new FileOutputStream(output_file_name)
        stream.write(data); 
    } catch (Exception e) {
        //Catch IOException errors
    }
    

    Hope it helps!