title: Access denied exception : testNG java.IOException
body: <p>I am new to automation testing in selenium<br>
  While executing testNG code in java maven project I got following issue :</p>
  
  <pre><code>[Utils] [ERROR] Access is denied
  *java.io.IOException*: Access is denied
      at java.io.WinNTFileSystem.createFileExclusively(Native Method)
      at java.io.File.createNewFile(Unknown Source)
      at org.testng.internal.Utils.writeFile(*Utils.java:176*)
      at org.testng.internal.Utils.writeFile(*Utils.java:149*)
      at org.testng.reporters.SuiteHTMLReporter.generateTableOfContents(SuiteHTMLReporter.java:611)
      at org.testng.reporters.SuiteHTMLReporter.generateReport(SuiteHTMLReporter.java:69)
      at org.testng.TestNG.generateReports(TestNG.java:1097)
      at org.testng.TestNG.run(TestNG.java:1022)
      at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
  [Utils] [ERROR] Access is denied
  java.io.IOException: Access is denied
      at java.io.WinNTFileSystem.createFileExclusively(Native Method)
      at java.io.File.createNewFile(Unknown Source)
      at org.testng.internal.Utils.writeFile(Utils.java:176)
      at org.testng.internal.Utils.writeFile(Utils.java:149)
      at org.testng.reporters.SuiteHTMLReporter.generateXmlFile(*SuiteHTMLReporter.java:101*)
      at org.testng.reporters.SuiteHTMLReporter.generateReport(*SuiteHTMLReporter.java:79*)
      at org.testng.TestNG.generateReports(*TestNG.java:1097*)
      at org.testng.TestNG.run(TestNG.java:1022)
      at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
  [Utils] [ERROR] Access is denied
  java.io.IOException: Access is denied
      at java.io.WinNTFileSystem.createFileExclusively(Native Method)
      at java.io.File.createNewFile(Unknown Source)
      at org.testng.internal.Utils.writeFile(Utils.java:176)
      at org.testng.internal.Utils.writeFile(Utils.java:149)
      at org.testng.reporters.SuiteHTMLReporter.generateIndex(SuiteHTMLReporter.java:170)
      at org.testng.reporters.SuiteHTMLReporter.generateReport(SuiteHTMLReporter.java:82)
      at org.testng.TestNG.generateReports(TestNG.java:1097)
      at org.testng.TestNG.run(TestNG.java:1022)
      at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
  </code></pre>
  
  <p>My classed looks like follows :
  TestBase.java</p>
  
  <pre><code>public class TestBase {
  public static WebDriver driver=null;
  public static Properties prop;
  
  public TestBase() {
      try {
          prop = new Properties();
          FileInputStream ip = new FileInputStream(
                  System.getProperty("user.dir")+"\\src\\main\\java\\com\\qa\\config\\config.properties");
          prop.load(ip);
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  public static void initialization() {
      String browserName = prop.getProperty("browser");
  
      if (browserName.equalsIgnoreCase("chrome")) {
          System.setProperty("webdriver.chrome.driver", "E:\\Automation_Testing\\AutomationTest\\chromedriver.exe");
          driver = new ChromeDriver();
      } else if (browserName.equalsIgnoreCase("firefox")) {
          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.getProperty("url"));
  }
  }
  </code></pre>
  
  <p>In this class I have written my execution code to create a student in my application. 
  Class name : StudentPageTest.java</p>
  
  <pre><code> public class StudentPageTest extends TestBase{
  
  LoginPage loginpage;
   StudentPage studentpage;
  
   public StudentPageTest() throws Exception {
      super();
  }
  
  @BeforeTest
  public void setUp() throws IOException {
      initialization();
      loginpage = new LoginPage();
      studentpage = new StudentPage();
  }
  
  @Test(priority = 1)
  public void loginTest() throws InterruptedException {
      loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
  }
  
  @Test(priority = 2)
  public void addStudent() throws InterruptedException, IOException {
  
      studentpage = new StudentPage();
      Thread.sleep(8000);
      studentpage.clickBy(studentpage.studentMenu);
      Thread.sleep(10000);
      studentpage.add_student();
  }
  }
  </code></pre>
  
  <p>I am calling this method to add student the functionality of this method is that it should create a student in my application</p>
  
  <pre><code>public void add_student() throws InterruptedException, IOException {
  
      clickBy(add_studentBtn);
      Thread.sleep(10000);
  
      sendText(stud_name, "Nayan");
      Thread.sleep(2000);
  
      sendText(stud_contactnum, "4565434455");
      Thread.sleep(2000);
  
      sendText(stud_email, "n1@gmail.com");
      Thread.sleep(2000);
  
      sendText(parentname, "Prakash");
      Thread.sleep(2000);
  
      sendText(parent_contactnum, "5543654344");
      Thread.sleep(2000);
  
      sendText(parent_email, "prksh@gmail.com");
      Thread.sleep(2000);
  
      clickBy(assigncourselink);
  
  
  
  }
  </code></pre>
  
  <p>Please comment if you require anything more to analyse.</p>