• java工作复习——格式化时间 ——判断某个路径(文件夹是否存在)——不存在则创建(创建的文件夹以当天日期命名)


    package jkcs;
    
    import java.io.File;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    public class jdcs 
    {
        
        public static void main(String[] args) throws InterruptedException, IOException 
        {
             //System.setProperty("webdriver.chrome.bin","‪C:\Program Files (x86)\Mozilla Firefox\firefox.exe");    //设置安装路径,防止系统找不到
            
    
             
             //WebDriver driver = new FirefoxDriver();
             //driver.get("http://www.baidu.com");
             //driver.manage().window().maximize();
             
             //Thread.sleep(5000);
             
    
             
             
            DateFormat dateformat1= new SimpleDateFormat("yyyy-MM-dd");  //创建一个data format对象
            Date date1 = new Date();  //利用Date()获取当前时间            
            String datex = dateformat1.format(date1);    //格式化时间,并用String对象存储        
            System.out.println(datex);   //打印格式化时间到控制台
            
    
            DateFormat dateformat2= new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");  //创建一个data format对象
            Date date2 = new Date();  //利用Date()获取当前时间            
            String datey = dateformat2.format(date2);    //格式化时间,并用String对象存储        
            System.out.println(datey);   //打印格式化时间到控制台
            
            
            
            DateFormat dateformat3= new SimpleDateFormat("HH-mm-ss");  //创建一个data format对象
            Date date3 = new Date();  //利用Date()获取当前时间            
            String dateu = dateformat3.format(date3);    //格式化时间,并用String对象存储        
            System.out.println(dateu);   //打印格式化时间到控制台
            
    
           // File file = new File();
       
            
            
            File dir1 = new File("C:\Users\del\Desktop\"+datex);    //新建一个时间名文件夹,指定目录
            dir1.mkdirs();
            
            
            System.out.println(dir1.exists()); //返回true,表示建立成功
            
            
            
            
            
            
            
            
            String x = "C:\Users\del\Desktop\中国";    //新建一个指定名称,指定目录
            File dir2 = new File(x);
            dir2.mkdirs();
    
            //dir1.exists()可以判断目录是否存在
             
            System.out.println(dir2.exists()); //返回true,表示建立成功
             
            
            
            
            
            String y = "C:\Users\del\Desktop\中国002";    //新建一个指定名称,指定目录
            File dir3 = new File(y);
            System.out.println(dir3.exists());       //此路径不存在,返回false
            
            if (!dir3.exists()) 
            {
                dir3.mkdirs();
            }
            
            System.out.println(dir3.exists());       //此路径创建成功,返回true
            
            
             //Thread.sleep(5000);
             
             //driver.quit();
    
        }
    }

    执行结果:

    2020-04-28
    2020-04-28-16-34-55
    16-34-55
    true
    true
    false
    true

  • 相关阅读:
    《天才在左,疯子在右》
    MVC思想概述
    java文件读写
    HTTP协议简单笔记
    自学Python_Day01
    Linux基础介绍篇
    PHP学习 Day_01
    Linux中部分命令英语全拼
    Linux学习基础命令(三)
    Linux学习基础命令(二)
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12795173.html
Copyright © 2020-2023  润新知