<%
String realPath = this.getServletContext().getRealPath("/");
out.write(realPath);
File file = new File("/test.crl");
String nameOfTextFile = application.getRealPath("test.crl");
out.write(nameOfTextFile);%>
new File()是以当前目录为路径的,而
String realPath = this.getServletContext().getRealPath(".");
out.write(realPath);
就是安装tomcat的路径:
D:\Documents and Settings\Administrator\「开始」菜单\程序\Apache Tomcat 4.0
String realPath = this.getServletContext().getRealPath("/");
out.write(realPath);
File file = new File("/test.crl");
String nameOfTextFile = application.getRealPath("test.crl");
out.write(nameOfTextFile);%>
new File()是以当前目录为路径的,而
String realPath = this.getServletContext().getRealPath(".");
out.write(realPath);
就是安装tomcat的路径:
D:\Documents and Settings\Administrator\「开始」菜单\程序\Apache Tomcat 4.0
String realPath = this.getServletContext().getRealPath(".");
out.write(realPath);得到的路径是:
D:\Program Files\Apache Tomcat 4.0\webapps\zteicca\.
正是该jsp页面的路径。
而用
File file = new File("/test.crl");
生成的文件却是在
D:\目录底下,确实找得到
但用:
application.getRealPath
打印的却是
D:\Program Files\Apache Tomcat 4.0\webapps\zteicca\test.crl但该目录却找不到这文件》原代码和打印结果如下:请各位高手继续知道
<%
String realPath = this.getServletContext().getRealPath("/");
out.write("**********realPath: ");
out.write(realPath);
File file = new File("/jgm.crl");
if(file.exists()){
boolean isDelete = file.delete();
out.write("**********AbsolutePath : "+isDelete+"/n");
} boolean bool = file.createNewFile();
long nFileLength = file.length();
out.write(file.getAbsolutePath());
out.write("************ getPath: ");
out.write(file.getPath());
out.write("************getRealPath:" );
String nameOfTextFile = application.getRealPath("jgm.crl");
out.write(nameOfTextFile);
nameOfTextFile = application.getRealPath("CRL.crl");
out.write("************getRealPath CRL.crl: ");
out.write(nameOfTextFile);
out.write("************ currDirector: ");
realPath = this.getServletContext().getRealPath(".");
out.write(realPath);
%>
**********realPath:
D:\Program Files\Apache Tomcat 4.0\webapps\zteicca\
**********AbsolutePath : true/n
D:\jgm.crl
************ getPath:
\jgm.crl
************getRealPath:
D:\Program Files\Apache Tomcat 4.0\webapps\zteicca\jgm.crl
************getRealPath CRL.crl:
D:\Program Files\Apache Tomcat 4.0\webapps\zteicca\CRL.crl
************ currDirector:
D:\Program Files\Apache Tomcat 4.0\webapps\zteicca\.
实际上该文件CRL.crl却在
D:\Documents and Settings\Administrator\「开始」菜单\程序\Apache Tomcat 4.0
目录底下
注:CRL.crl是在jsp月面用
File file = new File("CRL.crl");
s生成的
没太注意到application
application -> requestOK, I think:<%@ page import="java.io.*" %>
<%
String realPath = this.getServletContext().getRealPath("/");
out.write("**********realPath: ");
out.write(realPath);
File file = new File("/", "jgm.crl");
if(file.exists()){
boolean isDelete = file.delete();
out.write("<br/>**********AbsolutePath : "+isDelete+"/n");
} boolean bool = file.createNewFile();
long nFileLength = file.length();
out.write(file.getAbsolutePath());
out.write("<br/>************ getPath: ");
out.write(file.getPath());
out.write("<br/>************getRealPath:" );
String nameOfTextFile = request.getRealPath("jgm.crl");
out.write(nameOfTextFile);
nameOfTextFile = request.getRealPath("CRL.crl");
out.write("<br/>************getRealPath CRL.crl: ");
out.write(nameOfTextFile);
out.write("<br/>************ currDirector: ");
realPath = this.getServletContext().getRealPath(".");
out.write(realPath);
%>
AngusZhang(zhgapp) 真是高手,我试了n多办法这么就没想到,谢谢你们。
由于刚参加该论坛,麻烦告诉给分的办法
你们一人(10分)该问题已解决^_^!