Why do I get FileNotFoundException?

fileNotFoundException but file exists

  • in my FileInputStream I get a FileNotFoundException, but I know he file exists, I can download it with the webbrowser. It also works if I copy the Link from the exception to webbrowser. Rights are on RWX to everyone for testing, but this doesn't help. there are no special signs in the filename... I have no idea why this fails.. thx 4 help! EDIT: KeyStore ts = KeyStore.getInstance("PKCS12"); ts.load(new FileInputStream("http://192.168.1.1/ordner/myFile.p12"), passwKey); KeyManagerFactory tmf = KeyManagerFactory.getInstance("SunX509"); tmf.init(ts, passwKey); I changed the link for security reasons

  • Answer:

    You should use InputStream is = new URL("http://stackoverflow.com/").openStream(); instead of a FileInputStream.

Starbax at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

See exception message... probably you don't have permission "java.io.FileNotFoundException (Permission Denied)". you have to give permission to the user currently running the application.

user1065624

Are you giving FileInputStream a URL as a String? Then you are using http://docs.oracle.com/javase/6/docs/api/java/io/FileInputStream.html#FileInputStream%28java.lang.String%29 and it states: Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system. Maybe you'd rather use http://docs.oracle.com/javase/6/docs/api/java/net/URL.html#openStream%28%29 which would work on any kind of URL, including remote ones.

Miquel

From Java specification: Signals that an attempt to open the file denoted by a specified pathname has failed. This exception will be thrown by the FileInputStream, FileOutputStream, and RandomAccessFile constructors when a file with the specified pathname does not exist. It will also be thrown by these constructors if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing. Are you sure, any of the scenerio mentioned there is not occuring?

Azodious

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.