我的项目在
file:/C:/Documents%20and%20Settings/Administrator/桌面/y2java/
类文件在
file:/C:/Documents%20and%20Settings/Administrator/桌面/y2java/WebRoot/WEB-INF/classes/com/zy/y2java/dao/Configuration.class
上面是生成的的class 文件
我的properties文件的路径是下面的这个
C:\Documents and Settings\Administrator\桌面\y2java\WebRoot\WEB-INF\test.properties
现在我要从Configuration类中找到test.properties相对路径如何写在java里面相对路径是相对那个一个?
在web 里面相对路径是相对哪一个?

解决方案 »

  1.   

    action="<%=request.getContextPath() %>---webroot目录我来说下  ..(父目录)
    说个列子b.html为目标文件
    你先建立个文件夹root 里面有个文件HTML  a.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>a.html</title>
      </head>
      
      <body>
        <a href="html/b.html">href==b</a>
      </body>
    </html>在建立两个文件夹html HTML文件b.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>b.html</title>
      </head>
      
      <body>
        This is my HTML page. <br>
      </body>
    </html> 文件夹htmb HTML文件c.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>c.html</title>
      </head>
      
      <body>
        <a href="../html/b.html">href==b</a>
      </body>
    </html>
      

  2.   

    我上面的是在java类中找,一个文件不是界面上面
      

  3.   

    以下是我的一个小项目获得路径的方式 
    // tomcat的home目录
        private static String TOMCAT_HOME = System.getProperty("catalina.home");
      

  4.   

    那请参考
    http://hi.baidu.com/liangroger/blog/item/90a1d0583063c686810a1863.html
    //java 程序
    InputStream in = getClass().getClassLoader().getResourceAsStream("abc.properties"); // abc.properties放在webroot/WEB-INF/classes/目录下
    prop.load(in);
    in.close();OutputStream out = new FileOutputStream(path); // path为通过页面传入的路径
    prop.setProperty("abc", “abcccccc");
    prop.store(out, “–test–");
    out.close();3.只通过Java程序操作资源文件
    InputStream in = new FileInputStream("abc.properties"); // 放在classes同级
      

  5.   

    在eclipse里,把properties放在源文件的根目录,eclipse自动编译部署的时候会编译到该项目的classpath下面,只需要像楼上说的那样去取就可以了
      

  6.   

    test.properties的相对路径:
    <% 
        String path = request.getContextPath(); 
         path+="/test.properties";
    %>
      

  7.   

    建议你把test.properties 文件再向下放一层,到classes目录。然后在你的java类中,用getResource("/test.properties");来获取最好。
    在java里面相对路径是相对那个一个? 
    在java里,通常相对路径是相对于程序启动时所在的路径。
    在web 里面相对路径是相对哪一个? 
    这个不同的操作系统有所区别,
    在windows上,相对路径是相对于tomcat/bin目录
    在linux上,是相对于tomcat的启动目录。
      

  8.   

    相对路径就是起动JVM的路径,在java里,就是程序启动的路径,就是项目的根目录
    在WEB里,以TOMCAT为例,就是tomcat/bin,因为是在这个目录下起动的JVM