title: read/copy file inside dynamic web project in java
body: <p>I create a dynamic web app project using JSP/Servlet with eclipse. And I want to create a copy of "db.xls" file in the same place. </p>
  
  <p>I try to create a copy of the "db.xls", the copy will named out.xls but it won't. These files should be located inside the same folder "files". My code compile, db.xls is correctly read, but file out.xls is not created. </p>
  
  <p>What's wrong with my method ? Please help !</p>
  
  <pre><code>public void readExcel()
      {
          try{
  
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              URL url1 = classLoader.getResource("");
  
              // read db.xls
              wbook = Workbook.getWorkbook(new File(url1.getPath()+"/db.xls"));
  
              // create a copy of db.xls nammed out.xls
              wwbCopy = Workbook.createWorkbook(new File(url1.getPath()+"/out.xls"), wbook);
              shSheet = wwbCopy.getSheet(0);
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/ehwW4.png" alt="enter image description here"></p>
  
  <p>I move the file "db.xls" inside WEB-INF and use getServletContext().getRealPath("/WEB-INF") but the output file "out.xls" still not created.</p>
  
  <pre><code>public void readExcel()
      {
          try{
  
  //          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  //          URL url1 = classLoader.getResource("");
  
              String tomcatRoot = getServletContext().getRealPath("/WEB-INF");
  
              wbook = Workbook.getWorkbook(new File(tomcatRoot+"/db.xls"));
              wwbCopy = Workbook.createWorkbook(new File(tomcatRoot+"/out.xls"), wbook);
              shSheet = wwbCopy.getSheet(0);
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
      }
  </code></pre>