这样去找:InputStream fileIn = getClass().getResourceAsStream("/SampleServlet.properties");

解决方案 »

  1.   

    不改程序 
    把properties 文件放在tomcat哪个目录可以吗?
      

  2.   

    那就不一定了,按理论说,使用getResourceAsStream才可以获取classpath下面的文件。否则就是JVM的当前工作目录。启动Tomcat的方式不同这个目录也是可能不同的。
      

  3.   

    应该放到mytest或mytest/WEB-INF下
      

  4.   

    后来我自己这样解决的。
          URL thisPropertyUrl = SampleServlet.class.getResource("SampleServlet.properties");
          String thisPropertyPath = thisServletUrl.getPath();
          File file = new File(thisPropertyPath);