5 Replies Latest reply: Mar 7, 2008 4:41 AM by 807591 RSS

    java.io.FileNotFoundException:

    807591
      hi,
      i am using a property reader for reading some value's like
      property.load(new FileInputStream("configFiles/config.properties"));
      src
        -->configFiles
               --> config.properties
        -->org.com
               -->Ainc.java
               -->Bdn.java
      i am trying to access the property file from Ainc.java


      when i tried as above i am getting the error as
      java.io.FileNotFoundException: configFiles/config.properties (The system cannot find the file specified)
      can any one suggest me what is wrong with path.
      ThanQ
      Han
        • 1. Re: java.io.FileNotFoundException:
          807591
          You cannot feed it with classpath resources. The java.io.File expects absolute file system level paths (e.g. c:/some/path/to/configFiles/config.properties). You should be using ClassLoader#getResourceAsStream() instead.
          • 2. Re: java.io.FileNotFoundException:
            807591
            new FileInputStream("configFiles/config.properties") will open a file relative to your current directory.

            You can see exactly what you are trying to open with:
            import java.io.File;
            import java.io.FileInputStream;
            import java.io.IOException;
            import java.util.Properties;
            
            public class A {
                public static void main(String[] args) {
                    Properties property = new Properties();;
            
                    File propFile = new File("configFiles/config.properties");
                    try {
                        System.out.println("Trying to open " + propFile.getCanonicalPath());
                        property.load(new FileInputStream(propFile));
                    } catch(IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            }
            • 3. Re: java.io.FileNotFoundException:
              807591
              Yes, that file would be relative to the current working directory. I wouldn't rely too much on that, it would bite you if you're going to use it at different environments. Just access it as a classpath resource, which it already is, assuming that the /src path is known in the classpath.
              • 4. Re: java.io.FileNotFoundException:
                807591
                it is working in the localmachine. but when i try to access from WebContainer it is showing error. I need to copy the .War file to the Container.

                Is there any other ways....?
                ThanQ
                • 5. Re: java.io.FileNotFoundException:
                  807591
                  It woult help us both more if you don't ignore errors, but actually interpret it and share it with us if you stucks. Errors aren't there to bite you, but to help you in finding the cause and solve the problem.