文件属性的取得
取出目录中文件的方法<%@ page contentType="text/html;charset=gb2312"%>
![]()
<%@ page import="java.util.Date,java.io.*"%>
![]()
<html>
![]()
<head>
![]()
<title>文件属性的取得</title>
![]()
</head>
![]()
<body>
![]()
<%
![]()
String path=request.getRealPath("/");
![]()
File f=new File(path,"ReadData.txt");
![]()
if(f.exists())...{
![]()
%>
![]()
<%=f.getName()%>的属性如下:<br><br>
![]()
文件长度为:<%=f.length()%>
![]()
<%=f.isFile()?"是文件":"不是文件"%><br>
![]()
<%=f.isDirectory()?"是目录":"不是目录"%><br>
![]()
<%=f.canRead()?"可读取":"不可读取"%><br>
![]()
<%=f.canWrite()?"可写入":"不可写入"%><br>
![]()
<%=f.isHidden()?"是隐藏文件":"不是隐藏文件"%><br>
![]()
文件的最后修改日期为:<%=new Date(f.lastModified())%><br>
![]()
<%
![]()
}else...{
![]()
f.createNewFile();//在当前目录下建立一个名为ReaData.txt的文件
![]()
%>
![]()
<%=f.getName()%>的属性如下:<br><br>
![]()
文件长度为:<%=f.length()%>
![]()
<%=f.isFile()?"是文件":"不是文件"%><br>
![]()
<%=f.isDirectory()?"是目录":"不是目录"%><br>
![]()
<%=f.canRead()?"可读取":"不可读取"%><br>
![]()
<%=f.canWrite()?"可写入":"不可写入"%><br>
![]()
<%=f.isHidden()?"是隐藏文件":"不是隐藏文件"%><br>
![]()
文件的最后修改日期为:<%=new Date(f.lastModified())%><br>
![]()
<%
![]()
}
![]()
%>
![]()
</body>
![]()
</html>
<%@ page contentType="text/html;charset=gb2312"%>
![]()
<%@ page import="java.io.*"%>
![]()
<html>
![]()
<head>
![]()
<title>取出目录中文件的方法--列出目录中的文件</title>
![]()
</head>
![]()
<body>
![]()
<%
![]()
String path=request.getRealPath("/");
![]()
File d=new File(path);//建立当前目录中文件的File对象
![]()
File list[]=d.listFiles();//取得代表目录中所有文件的File对象数组
![]()
out.println("<font color=#ff0000>" + path + "目录下的文件:</font><br>");
![]()
for(int i=0;i<list.length;i++)...{
![]()
if(list<I>.isFile())...{
![]()
out.println(list<I>.getName() + "<br>");
![]()
}
![]()
}
![]()
out.println("<br><font color=#ff0000>" + path + "目录下的目录:</font><br>");
![]()
for(int i=0;i<list.length;i++)...{
![]()
if(list<I>.isDirectory())...{
![]()
out.println(list<I>.getName() + "<br>");
![]()
}
![]()
}
![]()
%>
![]()
</body>
![]()
</html>
