title: Invoking a constructor with a file as an argument
body: <p>I have a class <code>SpellingSuggestor</code>, whose constructor has the signature </p>
  
  <hr>
  
  <p><code>public SpellingSuggestor(File file) throws IOException { // something }</code></p>
  
  <p>I want to invoke its constructor from another class. The code goes something like this </p>
  
  <pre><code>public class NLPApplications
      public static void main(String[] args) {    
          String w= "randomword";
          URL url = getClass().getResource("big.txt");
          File file = new File(url.getPath());
  
          System.out.println((new SpellingSuggestor(file)).correct(w));   
      }
  }
  </code></pre>
  
  <p>But the above shows error in the <code>URL url..</code> line saying</p>
  
  <ol>
  <li>URL cannot be resolved to a type.</li>
  <li>cannot make a static reference to the non-static method getClass() from the type Object.</li>
  </ol>
  
  <p>What is going wrong ? </p>
  
  <hr>
  
  <p>I looked at this question  <a href="https://stackoverflow.com/questions/3309899/how-to-pass-a-text-file-as-a-argument">How to pass a text file as a argument?</a>. I am not comfortable with handling files in Java and so this question. </p>