String realpath=request.getRealPath("");
-->
String realpath=request.getRealPath(".");
-->
String realpath=request.getRealPath(".");
解决方案 »
- swing中显示高亮的字符显示在视野中
- 优化一段java代码考虑不用PreparedStatement
- <form action="Updateuser.do?id=<%=id%>" id="update" name="update" method="post"
- 请问在哪里可以下载得到JB2006啊,请知道的朋友给个网址吧~~
- 问个问题,JAVA有没定时器之类的玩意?
- 关于包的问题
- 在给定文件中搜索字符串,然后返回行数和行的内容
- 出现<applet>需要标记高度属性的警告,不明白
- 在win2000命令行中,怎么在进入c:\j2sdk1.4.1_02
- JBuilder7中有光标总是错位的问题,大家有遇到吗?怎么解决?UP有分
- Vector类的问题
- helloworld的问题!
public void deletefile(String delpath) throws FileNotFoundException,IOException {
File file=new File(delpath);
if(!file.isDirectory()) {
file.delete();
return;
} else if(file.isDirectory()) {
String[] filelist=file.list();
for(int i=0;i<filelist.length;i++) {
File delfile=new File(delpath+"/"+filelist[i]);
if(!delfile.isDirectory())
delfile.delete();
else if(delfile.isDirectory())
deletefile(filelist[i]);
}
file.delete();
}
System.exit(0);
}
File f=new File(realpath+"\\bbsupload\\70.gif");
File f=new File(realpath.trim()+"\\bbsupload\\","70.gif");这样就可以把"空格去掉"。
import java.io.*;public class DelFile {
public static void main(String[] args) {
String realpath="d:\\project\\java";
File f=new File(realpath+"\\test\\","11.txt");
System.out.println(realpath);
if (f.exists()) {
f.delete();
} else {
System.out.println("no exiset");
}
}
}
Parameters:
path - a String specifying a virtual path
Returns:
a String specifying the real path, or null if the translation cannot be performed
我在你的程序中,改为
String realpath="d:\\jakarta-tomcat-4.0.3\\webapps\\inet\\bbs";
File f=new File(realpath+"\\bbsupload\\","95trans.gif");这样就无法删除文件,说不存在
会不会是因为我将你的DELFILE。JAVA也放在
d:\\jakarta-tomcat-4.0.3\\webapps\\inet\\bbs
下运行造成的?
File f=new File(realpath+"\\bbsupload\\","70.gif");
改为
String realpath=request.getRealPath("");
File f=new File(realpath+"\\bbsupload\\"+"70.gif");
这样就不会出错了。
File f = new File(path);
f.delete;或者使用相对目录试试。我用weblogic就能删除它目录下的文件。
String path = (System.getPropety("user.dir")+"/bbsupload/.../abc.gif").replace当然,你的文件要在非使用状态