写了一个web工程,其中有个servlet程序,生成一个xml文件,把web项目部署到tomcat,FileOutputStream路径该怎么写,才能让文件生成在部署好的工程文件夹里。

解决方案 »

  1.   

    是这样的
    URL url = new URL("."):
    代表了
    WEB-INF/classes所以如果你要放在其它地方,你就用相对路径吧
    URL url = new URL("mypackage/");
    URL url = new URL("../../images/");
      

  2.   

    第二,如果你非得用绝对的路径,请参考这段代码
    ServletContext con=getServletContext(); 
    String savePath = con.getRealPath("/");
      

  3.   

    ServletContext.getRealPath(String path)