Chetan Joshi
Chetan Joshi

Reputation: 349

How do I handle this FileNotFoundException?

    File file=new File("login.properties");
    FileInputStream input=null;
    try{
         input=new FileInputStream(file);// line33
    }
    catch(FileNotFoundException e )
    {
        e.printStackTrace();
    }
    Properties prop =new Properties();
    prop.load(input);
    input.close();

I'm getting FileNotFoundException at line33. i have "login.properties" file in WebContent folder. Where do I exactly place that file?

Upvotes: 0

Views: 58

Answers (1)

Anurag Anand
Anurag Anand

Reputation: 498

I will take it as you are trying to make a webapp.

You can access a path using request.getRealPath(request.getServletPath()); after that you can add the rest of the path of your file.

For example in weblogic you will get your path till your domain c:\oracle\middleware\oracle_home\user_projects\domains\YourDomain\ returned by above code.

your file might reside in applications\YourApplication\WEB-INF\login.properties inside YourDomain folder. So use above code to get path till your domain, then add rest of the path yourself.

The best way is to put the path in web.xml using context-param

<context-param>
<param-name>loginPropFileLoc</param-name>
<param-value>c:\oracle\middleware\oracle_home\user_projects\domains\YourDomain\YourApplication\WEB-INF\login.properties</param-value>
</context-param>

Then access the login properties file.Through this value.

ELSE put the properties file in the same directory where your class file is present. If your class file is in \abcd\ReadProperty.class then put property file as \abcd\login.properties

Upvotes: 1

Related Questions