Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HTML <img> tag and src attribute as a byte[]

807605Jul 16 2007 — edited Jul 17 2007
Hi everybody

I have a question is it possible to send a byte[] to the src attribute in a <img> HTML tag. What i would like to gain is a way of reading an img file from the jar in a custom tag which is no problem. Problems start when i want to send a byte[] which I have read from the InputStream to the StringBuffer which contains the HTML code.
byte[] dataByte = null;
String charEncoding = "UTF-8";
InputStream in = imageURL.openStream(); //InputStream to the img file inside a jar
StringBuffer buffer = new StringBuffer();
StringBuffer sb = new StringBuffer();
String imgData = "";
int data;
while((data = in.read()) != -1)
{
 buffer.append(new Integer(data).toString(), charEncoding);						
}
imgData = buffer.toString();
dataByte = imgData.getBytes();
The problem starts in this line, i think i need some encoding to do this.
sb.append("<img src=\""+dataByte.toString()+"\">");
thx in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 14 2007
Added on Jul 16 2007
6 comments
3,475 views