java.io.FileNotFoundException:。\ cfg \ users(系统找不到指定的路径)

时间:2018-09-23 12:41:46

标签: java jsp tomcat web servlet-3.0

我已经创建了一个动态Web项目(用于生成和发送报告)

Eclipse中的项目层次结构

Project
  src(folder)
         -metier(Package)
                  -Util.java(Class)
         -web
                  -ControlleurServlet.java (Servlet)  
  cfg(folder)
         -USERS(file) 

  WebContent
         - gui.jsp (Html form)

当我将Util类(方法:sendMail)作为Java项目运行时,它正在工作:

实用程序类:

public class Util {
    static String cvsSplitBy = ";";
public  static String MAILCONFIGURATION="./cfg/mailConfiguration";
public  static String USERS="./cfg/users";
public  static String SHIFTS="./cfg/shifts";
.
.
.

sendMail方法检索文件中的某些数据。

但是当我在服务器上运行项目并从Servlet调用sendMail时,出现此错误:

INFO: Server startup in 10135 ms
java.io.FileNotFoundException: .\cfg\users (The system cannot find the path specified)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at metier.Util.getUsers(Util.java:130)
    at web.ControleurServlet.doGet(ControleurServlet.java:37)
    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:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
    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(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

能请你帮忙吗?

致谢

1 个答案:

答案 0 :(得分:0)

servlet上下文没有指向保存文件的相同路径,

因此您可以检查上下文路径并将文件夹保存在适当的位置。

应该可以解决您的问题