zoukankan      html  css  js  c++  java
  • java删除文件及其目录

    1.删除指定文件路径

     1 public @ResponseBody
     2     String deleteFiles(HttpServletRequest request) {
     3         log.info(this.getClass().getSimpleName() + "."
     4                 + Thread.currentThread().getStackTrace()[1].getMethodName()
     5                 + "()------start");
     6         // 身份校验
     7         String random = request.getParameter("random");
     8         String checkCode = request.getParameter("checkCode");
     9         String reCheckCode=MD5Util.encrypt("pplovemm"+random.substring(random.length()-6));
    10         String result = "";
    11         if(reCheckCode.equals(checkCode)){ 
    12            // 指定路径文件
    13             String newFilePath="E:\video\2017-07-07\";
    14             log.info("Delete file or path:"+newFilePath);
    15             System.out.println("Delete file or path:"+newFilePath);
    16             if (newFilePath.startsWith(newFilePath) && clearFiles(newFilePath)) {
    17                 result = "success";
    18             } else {
    19                 result = "fail";
    20             }
    21             log.info(this.getClass().getSimpleName() + "."
    22                     + Thread.currentThread().getStackTrace()[1].getMethodName()
    23                     + "()--------end");
    24             return result;
    25         }else {
    26             result = "fail";
    27             log.info(this.getClass().getSimpleName() + "."
    28                     + Thread.currentThread().getStackTrace()[1].getMethodName()
    29                     + "()-身份校验失败--end");            
    30             return result;
    31         }        
    View Code

    2.clearFiles方法:

     1     // 删除文件和目录
     2     private static boolean clearFiles(String workspaceRootPath) {
     3         File file = new File(workspaceRootPath);
     4         if (file.exists()) {
     5             deleteFile(file);
     6         }
     7         // resources 文件夹被删除后需新建
     8         if (!file.exists() && workspaceRootPath.endsWith("resources")) {
     9             return file.mkdir();
    10         }else if(!file.exists()){
    11             return true;
    12         }
    13         return false;
    14     }
    View Code
  • 相关阅读:
    Android中fragment之间和Activity的传值、切换
    javascript--经典实例锦集
    Android中ListView动态加载数据
    Android开发之调用系统图库及相机
    Android 相机开发详解
    RTSP实例解析
    【Android UI设计与开发】第18期:滑动菜单栏(三)SlidingMenu动画效果的实现
    js 第二小步
    JavaScript初步+基本函数
    javaweb实战开始
  • 原文地址:https://www.cnblogs.com/pengpengzhang/p/7262786.html
Copyright © 2011-2022 走看看