我的项目在
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 里面相对路径是相对哪一个?
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 里面相对路径是相对哪一个?
说个列子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>
// tomcat的home目录
private static String TOMCAT_HOME = System.getProperty("catalina.home");
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同级
<%
String path = request.getContextPath();
path+="/test.properties";
%>
在java里面相对路径是相对那个一个?
在java里,通常相对路径是相对于程序启动时所在的路径。
在web 里面相对路径是相对哪一个?
这个不同的操作系统有所区别,
在windows上,相对路径是相对于tomcat/bin目录
在linux上,是相对于tomcat的启动目录。
在WEB里,以TOMCAT为例,就是tomcat/bin,因为是在这个目录下起动的JVM