I am reading an image from web-app/images and creating a duplicate of same in same location with different name. A Grails Application.
I am getting the real path of the file using the follwing code,
def serveletContext = ServletContextHolder.servletContext
def filePath = serveletContext.getRealPath( "web-app/images" )
def actFile= new File(filePath+ "myimg.png")
final BufferedImage image = ImageIO.read(actFile)
This is working fine in my devlopment environment. Both read and write happening fine. When I am deploying WAR of the application in Tomcat i'm getting the exception
java.lang.reflect.UndeclaredThrowableException at BootStrap$_closure1.doCall(BootStrap.groovy:39) at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308) at grails.util.Environment.executeForEnvironment(Environment.java:301) at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: javax.imageio.IIOException: Can't read input file!
Please tell me how to resolve this. Or I can do the same by using relative path instead real path in anyway?