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);   //打印格式化时间到控制台      
             
            // File file = new File();
        
             
             
             File dir1 = new File("C:\\Users\\del\\Desktop\\"+datex);    //新建一个时间名文件夹,指定目录
             dir1.mkdirs();
             
             
             String x = "C:\\Users\\del\\Desktop\\中国";    //新建一个指定名称,指定目录
             File dir2 = new File(x);
             dir2.mkdirs();

//dir1.exists()可以判断目录是否存在
Thread.sleep(
10000); }catch (Exception e) { e.printStackTrace(); }finally { driver.quit(); } } }

执行结果:

2020-02-11

猜你喜欢

转载自www.cnblogs.com/xiaobaibailongma/p/12296766.html
今日推荐