Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:23:17+00:00 2026-06-13T06:23:17+00:00

here is my java code that construct the base64 String from image. Then place

  • 0

here is my java code that construct the base64 String from image. Then place the base64 String html, to view
the constructed image, but image is not constructed somehow

public void getBase64String() throws FileNotFoundException {
    FileInputStream itStrm = new FileInputStream(
    "E:\\image\\56255254-flower.jpg");//image is lying at http://danny.oz.au/travel/mongolia/p/56255254-flower.jpg
    String str = itStrm.toString();
    byte[] b3 = str.getBytes();
    String base64String = new sun.misc.BASE64Encoder().encode(b3);
    //output of base64String is amF2YS5pby5GaWxlSW5wdXRTdHJlYW1AMTdlMDYwMA==
  }

Now in html page i placed the output of base64String in img tag to view the image.But image does not shows up
(instead it display the cross image icon). I am not getting image is not displayed from base64 String below?

      <HTML>
      <BODY>
           <img    src="data:image/jpeg;base64,amF2YS5pby5GaWxlSW5wdXRTdHJlYW1AMTdlMDYwMA=="/>

     </BODY>
     </HTML>

EDIT:- Thanks Folks, i used byte[] bytes = IOUtils.toByteArray(is);. It worked for me!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:23:17+00:00Added an answer on June 13, 2026 at 6:23 am

    This: String str = itStrm.toString() is not the image but the toString() representation of the FileInputStream instance.

    You’ll have to read the bytes from the stream and store them in a byte array. And, for performance reasons, buffer the stream:

    BufferedInputStream itStrm = new BufferedInputStream(FileInputStream(
        "E:\\image\\56255254-flower.jpg"));
    

    Further reading (Spoiler: solution inside)

    • Convert InputStream to byte array in Java
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the piece of code that I have used for Java 5.0 TreeSet<Integer>
I happen to come across a Java code at my work place. Here's the
I am trying to call a java script function from java code. Here is
// Here's my code: Main Class: import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.BufferStrategy;
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
here is the code (java): class prime { public static boolean prime (int a,
Here is a simple piece of code: import java.io.*; public class Read { public
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.