<%--List8_4_1.jsp--%>
<%@ page import="java.io.File"%>
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
  <head><title>操作文件和目录</title></head>
  <body>
     <%
         File dir=new File("F:/Mydir");
         //创建目录
         if(!dir.mkdir())
         System.out.println("Failed to Create directory:F:/Mydir");
         //创建多层目录
         File subDir=new File("F:/Mydir/subDir/subDir2");
         if(!subDir.mkdirs())
         System.out.println("Failed to Create directory:F:/Mydir/subDir/subDir2");
         //创建文件
         File file=new File("F:/Mydir/subDir/subDir2/file.txt");
         if(!file.createNewFile())
         System.out.println("Failed to Create file:F:/Mydir/subDir/subDir2/file.txt");

         //删除文件
         if(!file.delete())
         System.out.println("Failed to delete file:F:/Mydir/subDir/subDir2/file.txt");
         //删除子目录
         if(!subDir.delete())
             System.out.println("Failed to delete directory:F:/Mydir/subDir/subDir2");
          //必须先将目录清空才能删除，否则删除会失败
         if(!dir.delete())
         {
              System.out.println("Failed to delete directory:F:/Mydir");
             File subDir2=new File("F:/Mydir/subDir/");
             subDir2.delete();
             dir.delete();
         }
     %>
  </body>
</html>