文件的建立、检查与删除[java]
<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>文件的建立、检查与删除</title>
</head>
<body>
<%
String path = request.getRealPath("");
out.println(path);
out.println("<br/>");
String ph = "/html/news/2008/5/16/";
ph = ph.replace("/",File.separator);
out.println("path+ph="+path+ph);
out.println("<br/>");
File f = new File(path+ph, "200851633128-4168.htm");
out.println(f);
out.println("<br/>");
out.println(f.exists());
out.println("<br/>");
if (f.exists()) {//检查File.txt是否存在
f.delete();//删除File.txt文件
out.println(path + "\\200851633128-4168.htm 存在,已删除。");
} else {
f.createNewFile();//在当前目录下建立一个名为File.txt的文件
out.println(path + "\\200851633128-4168.htm 不存在,已建立。");//输出目前所在的目录路径
}
%>
来自:http://www.pconline.com.cn/pcedu/empolder/gj/java/0502/559401.html
lunzi
2008-06-17 09:39:06
评论:0
阅读:192
引用:0
