title: Java how to user JFileChooser to save a excel file created by Apache POI
body: <p>I want to save a spreadsheet file to a user custom file folder, people suggest to use <code>JFileChooser</code>, but I actually don't know how to achieve it. I have my current example code here:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import org.apache.poi.xssf.usermodel.XSSFCell;
  import org.apache.poi.xssf.usermodel.XSSFRow;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class Example {
  
      public static void main(String[] args) throws FileNotFoundException, IOException {
          XSSFWorkbook workbook;
          File file = new File("example.xlsx");
          if (file.exists() == false) {
              workbook = new XSSFWorkbook();
              XSSFSheet exampleSheet = workbook.createSheet("1");
              XSSFRow firstRow = exampleSheet.createRow(1);
              XSSFCell cell = firstRow.createCell(0);
              cell.setCellValue("value");
  
              try ( 
                  //Write the workbook in file system
                  FileOutputStream out = new FileOutputStream(file)) {               
                      workbook.write(out);
                  }
          } else {
              // Sheet already exists
              System.out.println("File already exist");
          }
      }
  
  }
  </code></pre>
  
  <p>Currently it only save the file to the default project directory. But I want it to be saved to a user selected path with a user customized filename. <code>JFileChooser</code> seems like a good choice, but can someone show me how do I use it in my case?</p>