471,896 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

Problem in getting real path in JBoss Application server

Hello everyone,

I was testing a web app on Tomcat and I basically created a 'Temp' folder in the 'Web-content' folder of the project in Eclipse. I write files to that folder in my web app by using the following code:

Expand|Select|Wrap|Line Numbers
  1. String imagePath = getServletContext().getRealPath("/Temp/")+"\\"+userName+".png";
After doing this, I was able to download the file from http://localhost:8080/MyProjectName/Temp

When I switched to JBoss for the same application without making any changes, and after creating the 'Temp' folder in the same location, I keep facing a 'file not found' exception when I try to use the following code:

Expand|Select|Wrap|Line Numbers
  1. String imagePath = getServletContext().getRealPath("/Temp/")+"\\"+userName+".png";
  2. ImageIO.write((BufferedImage)returnValue, "jpg", new File(pathOfChart+"chart.jpg"));
It says 'The system could not find the path specified'.

Does anyone know why this is happening and/or how I could work around this?

Thanks in advance for your help.


Apr 23 '09 #1
9 10314
2,476 2GB
Don't use \\ for path separator in Windows? Always use \ for File Path Separator.
Apr 23 '09 #2
11,448 Expert 8TB
The poster is using a single back slash; it needs to be escaped in String literals.

kind regards,

Apr 23 '09 #3
2,476 2GB
<snipped> ............. Actually it would be , "always use / " ;)
Apr 23 '09 #4
I worked around that problem by creating a directory (if it doesn't automatically exist) at the servlet's start up. A "filePointer.mkdirs()" seemed to take care of that just fine. The same code works with that. Just thought I would put this up if anyone else faces a similar problem. Thanks for your help.


Apr 24 '09 #5
2,476 2GB
See, Have the code like this ...

Expand|Select|Wrap|Line Numbers
  1. String imagePath = getServletContext().getRealPath("/Temp/")+userName+".png";
Here i can see two paths you are using ...

Print two paths, and see what it results ;)
Use / always as "file path separator" what ever OS or server you are using.
First let me know which path the "System can't find" and what are print outs of "two paths". Check whether two paths exist or not.
Apr 24 '09 #6
785 Expert 512MB
Instead of using / or \, the best way (os-independent) is to use "File.separator" !

Always using / is not os-independent!
Apr 24 '09 #7
2,476 2GB
Yeah.. I Know.
I think if i put / then it would be running on any OS so far what implemented. Basically Windows offer \ and rest offers /.
But if you put / for Windows then Java can intelligently make it Windows compatible ;)
Apr 24 '09 #8
FYI, I tried printing the path when I had the earlier problem and it showed now problems whatsoever. If I hard-coded the path in the system (say "D:/Something/Somewhere") that would work just fine.
Apr 27 '09 #9
785 Expert 512MB
You are defining variable "imagePath", but don't use it!
Instead, you use "pathOfChart".

So why don't you print out these values and show them to us, or list the whole source code?

The calculation of imagePath seems correct.
You wrote if you hardcode the whole path it works.
So I guess the error is somewhere how you calculate "pathOfChart". Maybe it doesn't contain a backslash at the end? (it must, because you are concatenating directly the image name to it.)
Apr 30 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Chris Gatto | last post: by
1 post views Thread by Jochen Fromm | last post: by
7 posts views Thread by Vincent Delporte | last post: by
2 posts views Thread by mastery20 | last post: by
11 posts views Thread by rh00667 | last post: by
2 posts views Thread by walterbyrd | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.