加载属性文件

时间:2017-06-19 05:35:30

标签: java properties property-files

我在加载属性文件时遇到错误。 我收到以下错误:     java.io.FileNotFoundException:neosEntitelment.properties(系统不能

find the file specified)
        at java.io.FileInputStream.open0(FileInputStream.java)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at noes.Entitelment.CreateProperties.<init>(CreateProperties.java:45)
        at noes.Entitelment.NeosDatabase.oracleJdbcConnection(NeosDatabase.java:68)
        at noes.Entitelment.NeosDatabase.getDataByDB(NeosDatabase.java:20)
        at noes.Entitelment.SoapWebService.getEntitelmentDetails(SoapWebService.java:254)
        at noes.Entitelment.Entitelment.doGet(Entitelment.java:27)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
        at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:110)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

项目结构是:

Project
    -src
    -neosEntitelment.properties

这是我的代码

Properties prop = new Properties();
prop.load(new FileInputStream("neosEntitelment.properties"));
setNeoJdbcConnectionUrl(prop.getProperty("neo.jdbc.connection.url"));
setNeoUserName(prop.getProperty("neo.db.userName"));
setNeoPassword(prop.getProperty("neo.db.password"));

2 个答案:

答案 0 :(得分:0)

我建议你使用&#34; getClass.getResourceAsStream(&#39; /neOntitelment.properties')&#34;

答案 1 :(得分:-2)

放置文件&#34; neosEntitelment.properties&#34;进入&#34; src&#34; 。目录