title: How to convert an Image to base64 string in java?
body: <p>It may be a duplicate but i am facing some problem to convert the image into <code>Base64</code> for sending it for <code>Http Post</code>. I have tried this code but it gave me wrong encoded string.</p>
  
  <pre><code> public static void main(String[] args) {
  
             File f =  new File("C:/Users/SETU BASAK/Desktop/a.jpg");
               String encodstring = encodeFileToBase64Binary(f);
               System.out.println(encodstring);
         }
  
         private static String encodeFileToBase64Binary(File file){
              String encodedfile = null;
              try {
                  FileInputStream fileInputStreamReader = new FileInputStream(file);
                  byte[] bytes = new byte[(int)file.length()];
                  fileInputStreamReader.read(bytes);
                  encodedfile = Base64.encodeBase64(bytes).toString();
              } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              return encodedfile;
          }
  </code></pre>
  
  <p><strong>Output:</strong> [B@677327b6 <br> <br>
  But i converted this same image into <code>Base64</code> in many online encoders and they all gave the correct big Base64 string.</p>
  
  <p><strong>Edit:</strong> How is it a duplicate?? The link which is duplicate of mine doesn't give me solution of converting the string what i wanted.</p>
  
  <p><strong>What am i missing here??</strong> </p>