title: Java - creating new file, how do I specify the directory with a method?
body: <p>I know how to write a <code>file</code> to a specified directory by doing this:</p>
  
  <pre><code> public void writefile(){
  
      try{
          Writer output = null;
          File file = new File("C:\\results\\results.txt");
          output = new BufferedWriter(new FileWriter(file));
  
          for(int i=0; i&lt;100; i++){
             //CODE TO FETCH RESULTS AND WRITE FILE
          }
  
          output.close();
          System.out.println("File has been written");
  
      }catch(Exception e){
          System.out.println("Could not create file");
      }
  </code></pre>
  
  <p>But how do I go on specifying the directory, if the directory is set in a method? A method called <code>getCacheDirectory()</code> for example. Assuming that all necessary imports etc have been done..</p>
  
  <p>Thanks :).</p>