title: The process cannot access the file because it is being used by another process, while Renaming the Filepath?
body: <p><strong>I am giving the same File path for writing data(Pass/Fail Test report) into Excel File and the Renaming same filepath with Current date and Time at the End of Execution, But while renaming the same Filepath with Current Date and Time at the End of Execution i am getting one Exception and that is: java.nio.file.FileSystemException: C:\Users\skumari1\eclipse-workspace\CoreLinkAutomation\PCPAutomation.xlsx -&gt; C:\Users\skumari1\eclipse-workspace\CoreLinkAutomation\PCPAutomation1.xlsx + Validatedate(): The process cannot access the file because it is being used by another process.</strong></p>
  <pre><code>public class TestBase {
          public static WebDriver driver;
          public static Properties prop_config;
          public static Properties prop_filr_io; 
          
          public static String FilePath=&quot;C:\\Users\\skumari1\\eclipse-workspace\\CoreLinkAutomation\\PCPAutomation.xlsx&quot;; **Here i am providing the filepath to write data into Excel sheet.**
  
          public static String sheet_name=&quot;PCP(P)&quot;;
          public static String sheet_name1=&quot;PCP(S)&quot;;
          
             
        @BeforeClass
      public static void StartExecution()
      {
          System.out.println(&quot;Start Execution&quot;);
          
      }
      
          
          
          @BeforeMethod
          public static void initialization() throws IOException
          {
              try {
                  prop_config=new Properties();
                  prop_config.load(new FileInputStream(&quot;C:\\Users\\skumari1\\eclipse-workspace\\CoreLinkAutomation\\src\\main\\java\\com\\corelink\\resources\\config.properties&quot;));
                  String browserName=prop_config.getProperty(&quot;browser&quot;);
      
                  if(browserName.equals(&quot;chrome&quot;))
                  {
                      System.setProperty(&quot;webdriver.chrome.driver&quot;,&quot;H:\\udemy\\chromedriver_win32 (1)\\chromedriver.exe&quot;);
                      driver=new ChromeDriver();
                  }
                  else if(browserName.equals(&quot;FF&quot;))
                  {
                      System.setProperty(&quot;webdriver.gecko.driver&quot;,&quot;C:\\Users\\skumari1\\eclipse-workspace\\CoreLinkAutomation\\geckodriver.exe&quot;);
                      driver=new FirefoxDriver();
                  }
                  
                  driver.manage().window().maximize();
                  driver.manage().deleteAllCookies();
                  driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
                  driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);
                  driver.get(prop_config.getProperty(&quot;url&quot;));
                  prop_filr_io=new Properties();
                  prop_filr_io.load(new FileInputStream(&quot;C:\\Users\\skumari1\\eclipse-workspace\\CoreLinkAutomation\\src\\main\\java\\com\\corelink\\resources\\file_constants.properties&quot;));
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              }
              
              
      
              
              
          }
          @AfterMethod
          public void screenShot(ITestResult result) throws Exception{
               //using ITestResult.FAILURE is equals to result.getStatus then it enter into if condition
               if(ITestResult.FAILURE==result.getStatus()){
               try{
               // To create reference of TakesScreenshot
               TakesScreenshot screenshot=(TakesScreenshot)driver;
               // Call method to capture screenshot
               File src=screenshot.getScreenshotAs(OutputType.FILE);
               // Copy files to specific location 
               // result.getName() will return name of test case so that screenshot name will be same as test case name
               //FileUtils.cleanDirectory(new File(&quot;./FailedTestCases&quot;+result.getName()+&quot;.png&quot;));
               Thread.sleep(5000);
               FileUtils.copyFile(src, new File(&quot;./FailedTestCases/&quot; +result.getName()+&quot;.png&quot;));
               System.out.println(&quot;Successfully captured a screenshot&quot;);
      
               }catch (Exception e){
               System.out.println(&quot;Exception while taking screenshot &quot;+e.getMessage());
               } 
               }
              
               driver.quit();
               }
          
          @AfterClass
          
              public void EndExecution() throws Exception{
              
              
              
          
              Path source = Paths.get(&quot;C:\\Users\\skumari1\\eclipse-workspace\\CoreLinkAutomation\\PCPAutomation.xlsx&quot;);**The same Filepath using here**
      
              try{
      
                  Files.move(source, source.resolveSibling(&quot;PCPAutomation1.xlsx + Validatedate()&quot;),
                            StandardCopyOption.REPLACE_EXISTING);
      
              } catch (Exception e) {
                e.printStackTrace();
              }
              
              }
          public static String Validatedate() {
              SimpleDateFormat dateFormat = new SimpleDateFormat(&quot;dd-MM-yyyy_HH_mm_ss&quot;);
              Date date = new Date();
              String date1= dateFormat.format(date);
              // System.out.println(&quot;Current date and time is &quot; +date1);
               return date1;
      }
      }
  
  
  public static void write_test_result(String result, String sheet_name, String filePath,int row_num,int col_num) throws EncryptedDocumentException, FileNotFoundException, IOException
      {
          
          Workbook wb = WorkbookFactory.create(new FileInputStream(filePath));
          Sheet sh = wb.getSheet(sheet_name);
          
          sh.getRow(row_num).createCell(col_num).setCellValue(result);
          //sh.createRow(row_num).createCell(col_num).setCellValue(result);
          wb.write(new FileOutputStream(filePath));
          //wb.close();
  
      
              }
  </code></pre>
  <p><strong>Here Created Method for Filepath and the Sheetname for writing data into excel sheet and Filepath i am providing in Base Class Before Execution you can check above in the code , Hence how do i close this program because wb.close is not working.</strong></p>
  <p>**If i am using Different Filepath then my code is working Fine, But Client Requirement is like Insert pass/Fail Test Report into Excel File and the same File should get Renamed as Updated Time Stamp at the end of Every Execution but when i am renaming it,i am getting this Exception,Can i get a Solution on this ? Is this possible to Rename the same Filepath which is in use already? **</p>