title: Convert base64 string to image at server side in java
body: <p>I have base64 String which I want to convert back to image irrespective of image format at server side. I tried it by using following code, image is getting created but when I am trying to preview it, showing error could not load image.   </p>
  
  <pre><code>public void convertStringToImage(String base64) {
          try {
              byte[] imageByteArray = decodeImage(base64);
  
              FileOutputStream imageOutFile = new FileOutputStream("./src/main/resources/demo.jpg");
              imageOutFile.write(imageByteArray);
              imageOutFile.close();
          } catch (Exception e) {
              logger.log(Level.SEVERE, "ImageStoreManager::convertStringToImage()" + e);
          }
      }
  
  
      public static byte[] decodeImage(String imageDataString) {
          return Base64.decodeBase64(imageDataString);
      }
  </code></pre>
  
  <p>what should I do so that my image will look properly?</p>