• java+selenium+new——创建一个文件,判断文件的目录知否存在,以及创建目录


    package rjcs;
    
    import java.io.File;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.interactions.Actions;
    
    public class a 
    {
        public static void main(String[] args)
        
        {
             System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");    //设置火狐的安装路径,防止系统找不到
                
             FirefoxDriver driver = new FirefoxDriver();        //初始化FireFox浏览器实例,并打开浏览器
             
            try
            {
                 driver.manage().window().maximize();         //最大化窗口
                 
                 Thread.sleep(5000);        
    
            
                 driver.get("https://www.baidu.com");  
                 
                 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);   //打印格式化时间到控制台      
                 
                 
                 
                 Thread.sleep(5000);
                 
                 File file = new File("C:\\Users\\del\\Desktop\\中国\\123.txt");
                 System.out.println(file.getParentFile());  //打印此文件的目录: C:\Users\del\Desktop\中国
                 System.out.println(file.getParentFile().exists());   //返回false说明不存在
                 
                 //下面则创建这个目录
                 
                 
                 System.out.println(file.getParentFile().mkdirs());   //目录创建成功,返回true
                 
                 System.out.println(file.getParentFile().exists());   //返回true,说明该目录已经存在
    

                  //最后创建这个文件

                    System.out.println(file.createNewFile());   //返回true  说明文件创建成功

    
    
                 Thread.sleep(10000);
                 
                 
            }catch (Exception e) 
            {
                e.printStackTrace();
            }finally 
            {
                driver.quit();
            
             }
        }
    }

    执行结果:

    2020-02-11
    C:\Users\del\Desktop\中国
    false
    true
    true
    true

  • 相关阅读:
    Protocol Buffer技术详解(语言规范)
    google protobuf 简单实例
    advStringGrid单元格文字垂直居中
    java中两个字符串如何比较大小
    List集合去除重复对象及equals()、hashCode()方法的作用
    Delphi中使用ActiveX的一些心得
    java List去重方式及效率对比
    Visual Studio Code 调整字体大小
    用最简单的例子实现jQuery图片即时上传
    Linux下绝对经典的命令
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12297417.html
Copyright © 2020-2023  润新知