错误如下:java.io.FileNotFoundException: srv/apache-tomcat-6.0.29/webapps/tdliveCenter/WEB-INF/jdbc.properties (No such file or directory)
我去srv/apache-tomcat-6.0.29/webapps/tdliveCenter/WEB-INF文件夹下看了,明明有这个文件啊下边是调用这个文件的代码String driver = "";
            URL url = BaseUtil.class.getClassLoader().getResource(
                    "../jdbc.properties");
            FileInputStream fis = new FileInputStream(new File(url.getPath()
                    .substring(1).replace("%20", " ")));
            Properties p = new Properties();
            p.load(fis);
            dbUrl = p.getProperty("tdlive.url");
            dbUser = p.getProperty("tdlive.username");
            dbPwd = p.getProperty("tdlive.password");
            driver = p.getProperty("driver");
            Class.forName(driver);

解决方案 »

  1.   

    URLDecoder.decode(String s, String enc)用这个解码,而且你把那个路径也输出来看看,是指向哪了
      

  2.   

    URL url = BaseUtil.class.getClassLoader().getResource("../jdbc.properties");
    路径问题。
    “.."引发
      

  3.   

    在qq群7463462问了精灵同学
    已经解决了
    InputStream fis  = BaseUtil.class.getResourceAsStream("/jdbc.properties");
    把jdbc.properties 放到src目录搞定~
      

  4.   

    看来你还是不明白 getResource / getResourceAsStream 怎么寻找资源的。
      

  5.   

    是在加入到classpath的目录、jar文件中寻找。你可以看看这个帖子:
    【解惑】深入jar包:从jar包中读取资源文件