This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes FileNotFoundException please help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "FileNotFoundException please help. " Watch "FileNotFoundException please help. " New topic
Author

FileNotFoundException please help.

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I have a java class that uses the file "keystore\test.keystore" in a web application. This keystore file is used to encrypt and decrypt the credit card on my web site. But when the method to encrypt the credit is
getting called I am getting the following error.

[STDOUT] java.io.FileNotFoundException: keystore\test.keystore (The system cannot find the path specified)

I guess the file has to be on the server and its not finding it where it supposed to be.
Where should I copy this file on to the server? I am currently testing this in my localhost and I use a jboss server.
Randall Fairman
Greenhorn

Joined: Apr 18, 2011
Posts: 29
Most likely, the error is due to a statement of the form

java.io.File f = new File(directory,filename);

How did you set the directory? It's probably not pointed to the right place.

From the error text you show, it looks like you said that the directory is "keystore". That might work, depending on what the root is relative from which File() interprets your given directory. Better would be for the directory to be a complete path, starting at the system's root directory.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I think the keystore folder should have been in the classes directory. Looks like it's working if it's in the classes directory.
Thank you for helping.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

With web applications you should always use the ServletContext.getRealPath method to turn paths relative to the web application root to absolute paths.

I wouldn't put the keystore folder in your classes folder; make it a direct sub folder of the WEB-INF folder. That would make the parameter to getRealPath "WEB-INF/keystore/test.keystore". Because it's in WEB-INF it cannot be found by trying to access it directly; only your web application itself has access to it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
I think that is a good idea.
Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileNotFoundException please help.
 
Similar Threads
Sign a jar with a third party certificate, using keytool and jarsigner
Questions about email encryption and signing with S/MIME
modify keystore
Keystore help
Encrypt WAR file using Keystore