File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFoundException please help.

 
PradeepPillai Pradeep
Ranch Hand
Posts: 186
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 186
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
PradeepPillai Pradeep
Ranch Hand
Posts: 186
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is a good idea.
Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic