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; } }
  • 相关阅读:
    学习笔记::有上下界的网络流
    zoj2314
    bzoj3261
    bzoj 1898
    bzoj4009
    bzoj4033
    bzoj3389
    bzoj2427
    uva 11825
    交换A与B值的四种方法
  • 原文地址:https://www.cnblogs.com/todarcy/p/15048235.html
Copyright © 2011-2022 走看看