title: Return a file from java method
body: <p>I have created a method which accepts the JSON response and export the data to Excel and CSV file. I want the method to accept the filename as a parameter, and return the File/FileHandle object from the method. </p>
  
  <p>Can anyone help me regarding this? </p>
  
  <p>I am using below code to export data from <strong>creteExcel</strong> and <strong>createCSV</strong>.</p>
  
  <pre><code>public void createExcel( PageModel pageModelRequest,PageModel pageModelResponse ){
          FileOutputStream outputStream=new FileOutputStream(new File("GridData.xlsx"));
          createGrid(pageModelResponse, sheet, workbook);
          workbook.write(outputStream);
          System.out.println("Excel Written");    
          outputStream.close();
          workbook.close();
  }
  
  public void createCSV(PageModel pageModelRequest,PageModel pageModelResponse){
          String csvFile = "/Users/abhinak4/Desktop/GridData.csv";        
          FileWriter writer = new FileWriter(csvFile);
          createGrid(pageModelRequest, pageModelResponse, writer);
  }
  </code></pre>
  
  <p>In the method <code>createGrid</code>, I am creating the workbook for excel, and I am appending the data, to the <code>writer</code> (writer.append). </p>
  
  <p>I want to know, how can I accept the fileName as parameters for <code>createExcel</code> and <code>createCSV</code> method, and return the file with the same name containing the data?</p>