JSP Water Mark code is not working -


i have created code error says "javax.imageio.iioexception: can't read input file!". please resolve.

<%@ page language="java" contenttype="text/html" import="java.awt.alphacomposite,java.awt.color,java.awt.font,      java.awt.graphics,java.awt.graphics2d,java.awt.image,java.awt.image.bufferedimage,java.io.file,java.io.fileoutputstream,      javax.imageio.imageio,javax.swing.imageicon,com.sun.image.codec.jpeg.jpegcodec,com.sun.image.codec.jpeg.jpegencodeparam,      com.sun.image.codec.jpeg.jpegimageencoder" %> <%   try {   font font;   file _file = new file("images/1.jpg");   image src = imageio.read(_file);   int width = src.getwidth(null);   int height = src.getheight(null);   system.out.println("x = "+width+" , y = "+height);   bufferedimage image = new bufferedimage(width, height, bufferedimage.type_int_rgb);   graphics g = image.creategraphics();   g.drawimage(src, 0, 0, width, height, null);   g.setcolor(color.red);   g.setfont(new font("verdana", font.bold, 20));    g.drawstring("www.somelink.com",  5, height - (new font("arial", font.bold, 20)).getsize() / 2 - 5);   g.dispose();    fileoutputstream fout = new fileoutputstream("after.jpg");   jpegimageencoder encoder = jpegcodec.createjpegencoder(fout);   encoder.encode(image);   fout.close(); } catch (exception ee) {   out.println("error occurred : "+ee); } %> 

i unable solve exception thrown.

unlike console programs, web applications in java not assume working directory. have give full path. in jsp can use application.getrealpath("/") base path of application:

file _file = new file(application.getrealpath("/")+"images/1.jpg"); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -