zoukankan      html  css  js  c++  java
  • Java new File新建文件夹与文件,并删除文件demo

      /**
         * 创建文件夹
         * */
        public static boolean mkDirectory(String path) {
            File file = null;
            try {
                file = new File(path);
                if (!file.exists()) {
                    return file.mkdirs();
                }
                else{
                    return false;
                }
            } catch (Exception e) {
            } finally {
                file = null;
            }
            return false;
        }
    
    /** * 新增文件夹与文件后进行删除 * */ public void test(){ String path = "/test/abc/"; String fileName = "file1.txt"; if(mkDirectory(path)){ log.info("mkdir ok "); } try{ File dir = new File(path); File file1 = new File(dir, fileName); file1.createNewFile(); }catch (IOException e){ log.info("error:" + e.getMessage()); } File file = new File(path + fileName); if (file != null) { if(file.exists()){ file.delete(); log.info("file:" + file.getAbsolutePath() + " del success"); file = null; }else{ log.info("file:" + file.getAbsolutePath() + " no exists"); } file = null; } }
  • 相关阅读:
    jQuery的选择器
    01-jQuery的介绍
    client、offset、scroll系列
    BOM
    定时器
    js中的面向对象
    javascript小练手
    DOM介绍
    关于DOM的事件操作
    伪数组 arguments
  • 原文地址:https://www.cnblogs.com/todarcy/p/15048235.html
Copyright © 2011-2022 走看看