zoukankan      html  css  js  c++  java
  • java对文件操作--01

    1、删除文件

    /**
         * delete file
         * 删除文件
         * @param fileName
         * @return
         */
        private boolean deleteDir(String fileName)
        {
            boolean flag = false;
            File file = new File(fileName);
            if(file.exists()){
                flag = delFile(file);
            }
            
            return flag;
        }
            
            /**
             * delete file
             * 删除文件
             * @param fileName
             * @return
             */
            private boolean delFile(File file) {
                if (!file.exists()) {
                    return false;
                }
    
                if (file.isDirectory()) {
                    File[] files = file.listFiles();
                    for (File f : files) {
                        delFile(f);
                    }
                }
                return file.delete();
            }

      2、获取项目根路径

    /**
             * 获取路径
             * @return
             */
            public String getWebRoot()
            {
                String realUrl = getClass().getProtectionDomain().getCodeSource()
                        .getLocation().getPath();
    
                String newUrl = "";
    
                if (realUrl.contains("/WEB-INF/"))
                {
                    newUrl = realUrl.substring(0, realUrl.lastIndexOf("WEB-INF/"));
                }
    
                realUrl = newUrl.replace("%20", " ");//此路径不兼容jboss
    
                return realUrl;
            }

      

  • 相关阅读:
    定位 -CLGeocoder
    定位
    定位
    定位- 汽车导航
    定位
    SVN
    githubRepository -- 使用
    git 常用指令
    ipad ------ 与iPhone的差别
    总结
  • 原文地址:https://www.cnblogs.com/ouyy/p/10445506.html
Copyright © 2011-2022 走看看