aspose file tools*
The moose likes Other Open Source Projects and the fly likes How to find JPG file path? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to find JPG file path?" Watch "How to find JPG file path?" New topic
Author

How to find JPG file path?

Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
Hi in my application we have to make PDF with JPG header, I can able to create PDF but while looking for the JPG path, I'm getting the FileNotFoundException.

If I give the following path, then I get the excpetion.



I wrote the above logic in Struts Action class

The Exception is


I might use the wrong path to locate: what is the wright way


Thanks,
Kumar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
Assuming the path is actually correct, it might be a permissions problem. The account used for the app server might not be allowed to access one of the directories, or the file itself.


Ping & DNS - my free Android networking tools app
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
Still struggling with this solution
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
hi Ulf,

did you get any alternate solution ?

please find for me.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
I'm certainly not going to try and find a solution for you, nor will anyone else. We don't know what you have tried, or how you have followed up on the idea I posted earlier, so any speculation on our part would be idle. You don't even seem to know if the path you're passing to the code is correct. These are all things you need to try, and if it still doesn't work then, report back here with what you tried and how it failed. Then we might be able to give further advice.
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
Hi Ulf,

I tried with many paths, but it's throwing FileNotFoundException.

Explanation :
When I ran the Standalone file to produce PDF file with JPG image, it was working. the code I used in Standalone is following .


I can see the JPG image in generated PDF without throwing any error.

When It comes to web application to generate PDF, I was getting FileNotFoundException in all cases. please see the following paths I have used

but my file path is different and files are located in project folder where FiskarsTeacher is located in other area.

when I ran the standalone application why it was working and in terms of web why it wasn't working. is there anything wrong?

could you please see the error and if possible give me the correct solution
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
Tell us what value "request.getContextPath()" has, and also the full path of the image.

How have you made sure that it is not a permissions problem?
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
hi Ulf,

the request.getContextPath() is getting context path (project name) ContextPath = /FiskarsTeacher


and I used the following path where exactly the images are available.
String jpgFile = request.getContextPath() + "/WebContent/pages/jpg/sports_header.jpg";

then I got the following exception.


here I'm not getting why application is looking in C: folder with context path.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
Originally posted by Ulf Dittmer:
How have you made sure that it is not a permissions problem?
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
Hi,

I came to resolve this issue, now I can see the image in PDF file. I used the following code base.



in the logs the codebase is showing the path WebContent/WEB-INF/classess.
according to this path, I created a jpg folder under srs folder and copied all jpgs there.

but i think its not good approach, is there anyway to get the path to find the jpgs in the exact posn ( WebContent/pages/jpg/*)

i think we need to look into the URL codebase object. please check it and do let me know.
John Secada
Greenhorn

Joined: May 31, 2012
Posts: 1
Simpson Kumar wrote:Hi,

I came to resolve this issue, now I can see the image in PDF file. I used the following code base.



in the logs the codebase is showing the path WebContent/WEB-INF/classess.
according to this path, I created a jpg folder under srs folder and copied all jpgs there.

but i think its not good approach, is there anyway to get the path to find the jpgs in the exact posn ( WebContent/pages/jpg/*)

i think we need to look into the URL codebase object. please check it and do let me know.



Thanxs man for your help

i had a similar problem . I needed the image to generate a pdf file. The solution came with this code :


with this I got the image correctly
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to find JPG file path?