简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM