title: No file path in dynamic web project in java eclipse
body: <p>I have a dynamic web project in eclipse. When I'm executing just WordFreq.java it works. If I want to execute same code in MyServlet.java > doGet method, I get this error: HTTP Status 500 - text.txt (The system cannot find the file specified).
  I copied my file (text.txt) everywhere :</p>
  
  <ul>
  <li>The project root folder</li>
  <li>The WebContent folder</li>
  <li>The src folder</li>
  <li>Any subdirectory in my project.</li>
  </ul>
  
  <p>and still get this error.</p>
  
  <p>Note: my workspace is in D:/.... and my Apache server is on C:/...
  I tried to change to full path but still doesn't work.</p>
  
  <p>WordFreq.java</p>
  
  <pre><code>package cpd;
  import java.io.*;
  import java.util.Scanner;
  
  public class WordFreq {
  
      public static void main(String[] args) throws IOException {
          File file1 = new File("text.txt");
          BufferedReader in = new BufferedReader(new FileReader(file1));
          String content = new Scanner(file1).useDelimiter("\\Z").next();
          CezarBun cezar = new CezarBun();
          System.out.println(cezar.criptare(content, 3));
          System.out.println("Frecventa literelor");
          System.out.println();
          int nextChar;
          char ch;
          double[] count = new double[26];
          while ((nextChar = in.read()) != -1) {
              ch = ((char) nextChar);
              if (ch &gt;= 'a' &amp;&amp; ch &lt;= 'z') {
                  count[ch - 'a']++;
              }
          }
          for (int i = 0; i &lt; 26; i++) {
              System.out.printf("%c %d", i + 'a', (int) count[i]);
              System.out.println("Frecventa: " + count[i] / file1.length() * 100 + "%");
          }
          in.close();
          try {
              /*create a buffered reader that connects to the console, we use it so we can 
               read lines*/
  
              BufferedReader in2 = new BufferedReader(new InputStreamReader(System.in));
              //read a line from the console
              String lineFromInput = in2.readLine();
              //create an print writer for writing to a file
              PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
              System.setOut(out);
              //output to the file a line
              out.println(lineFromInput);
              //close the stream
              out.close();
          } catch (IOException e1) {
              System.out.println("Error during reading/writing");
          }
      }
  }
  </code></pre>
  
  <p>MyServlet.java</p>
  
  <pre><code>package cpd;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.FileReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintStream;
  import java.io.PrintWriter;
  import java.util.Scanner;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class MyServlet
   */
  @WebServlet("/MyServlet")
  public class MyServlet extends HttpServlet {
  
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public MyServlet() {
          super();
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
       * response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          out.print("A pornit servlet-ul" + "&lt;br /&gt;");
      //inceput wordfreq
          File file1 = new File("text.txt");
          BufferedReader in = new BufferedReader(new FileReader(file1));
          String content = new Scanner(file1).useDelimiter("\\Z").next();
          CezarBun cezar = new CezarBun();
          System.out.println(cezar.criptare(content, 3));
          System.out.println("Frecventa literelor");
          System.out.println();
          int nextChar;
          char ch;
          double[] count = new double[26];
          while ((nextChar = in.read()) != -1) {
              ch = ((char) nextChar);
              if (ch &gt;= 'a' &amp;&amp; ch &lt;= 'z') {
                  count[ch - 'a']++;
              }
          }
          for (int i = 0; i &lt; 26; i++) {
              System.out.printf("%c %d", i + 'a', (int) count[i]);
              System.out.println("        Frecventa:      " + count[i] / file1.length() * 100 + "%");
  
          }
          in.close();
          try {
              //create a buffered reader that connects to the console, we use it so we can read lines
              BufferedReader in2 = new BufferedReader(new InputStreamReader(System.in));
              //read a line from the console
              String lineFromInput = in2.readLine();
              //create an print writer for writing to a file
              PrintStream out2 = new PrintStream(new FileOutputStream("output.txt"));
              System.setOut(out2);
              //output to the file a line
              out2.println(lineFromInput);
              //close the file (VERY IMPORTANT!)
              out2.close();
          } catch (IOException e1) {
              System.out.println("Error during reading/writing");
          }
      //sfarsit wordfreq
      // freq = new WordFreqBun();
          //freq.wf();
          out.print("&lt;br /&gt;");
          out.print("&lt;a href='http://localhost:8080/CpdApplication/'&gt;Inapoi la meniu&lt;/a&gt;");
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
       * response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      }
  }
  </code></pre>