title: how to generate a .txt file from a list whose title is an abbreviation of a full name
body: <p>this is what I'm trying to accomplish:</p>
  
  <p>To write a program code such that when the user is allowed to enter an  employee name from the given list of employees, the program will search for 
  the employee’s payroll data and then generate a report in the form of a .txt file,
  whose file name is the employee’s first initial of his / her first name, followed by 
  their complete last name. </p>
  
  <p>For example, if a report is generated for David Davies, the report will be located in the text file bearing the name DDavies.txt.</p>
  
  <p>I've generated the list and I know how to pick the records I'm looking for. My problem is in creating a text file based on the user selection. </p>
  
  <p>i.e How do I create a file DDavies.txt based on a user entering "David Davies" as 1 string.</p>
  
  <p>Since names have different lengths, that means each string length is potentially different so I can't pick out the characters by index alone (or I don't know how).</p>
  
  <p>Since each full name is in 1 string, I was thinking of writing a code to pick the very first character, then the following string after the break(space) BUT since it's all in 1 string and the length isn't fixed, I don't know how to accomplish that.</p>
  
  <p>And Filewriter doesn't help matters cos' I have to specify the .txt extension to create a text file so I don't know how to generate the text file dynamically (having a specified title) without entering the name myself.</p>
  
  <p>I was thinking of breaking the string apart into a first and last name basis but that will change the code fundamentally cos what I'm trying to accomplish is part of a larger program.</p>
  
  <p>Please pardon my long intro, this is my first time so I hope I'm being specific enough.</p>
  
  <p>Below is the code. (Please note that the report doesn't need to be displayed to the user, I just need it to be generated in that firstInitial-LastName format)Thanks guys!</p>
  
  <pre><code>//Report.java
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.text.DecimalFormat;
  import java.util.ArrayList;
  import java.util.Collections;
  
  import javax.swing.JOptionPane;
  
  
  public class Report {
  
      String firstLine = "", secondLine = "", thirdLine = "";
      double hours = 0, wages = 0;
      DecimalFormat twoDecimal = new DecimalFormat("0.00");
  
      static ArrayList&lt;String&gt; emps = new ArrayList&lt;String&gt;();
  
      public Report() throws Exception {
  
          //code here the logic to create a report for the user
          FileReader file = new FileReader("payroll.txt");
          BufferedReader buffer = new BufferedReader(file);
  
          String line;
  
          File check = new File("Overtime.txt");
          FileWriter file1;
  
          if (check.exists())
              file1 = new FileWriter("Overtime.txt", true);
          else
              file1 = new FileWriter("Overtime.txt");
  
          int count = 0;
          while ((line = buffer.readLine()) != null) {
              firstLine = line;
              secondLine = buffer.readLine();
              thirdLine = buffer.readLine();
  
              double grosspay;
              emps.add(line);
          }//end while
  
          buffer.close();
          file1.close();
  
          String empList = "";
  
          Collections.sort(emps);
          for (String str : emps) {
              empList += str + "\n";
          }
  
          //Employee Listing (names)                
          JOptionPane.showMessageDialog(null, "Name:\n" + empList, "Employee Listing",
                  JOptionPane.PLAIN_MESSAGE);
  
  
          //Get input then of desired employee name to save employee data to a file
          String userInput = "";
  
          while (userInput == null || userInput.equals("")) {
  
              userInput = JOptionPane.showInputDialog("To get a payroll report, enter a name from the list");
          }
  
          if (empList.toLowerCase().contains(userInput.toLowerCase())) {
  
              /*Upon retrieval of a CORRECT employee name that exists from the employee list, 
                open payroll.txt file, grab the employee data from the name given 
                and write the emp's data to a file given the  employee’s first initial of his / her first name,
                followed by their complete last name. **THIS IS WHERE I NEED HELP!!** */
  
              /**Examples of random names to choose from, we have David Davies, Hyacinth Ho, Betty Boop etc**/
  
  
              // "Report Generated" Notification
              JOptionPane.showMessageDialog(null, "Report Generated.", "Result", JOptionPane.PLAIN_MESSAGE);
          }
  
          //Error Message
          else {
              JOptionPane.showMessageDialog(null, "Error!! Name invalid or doesn't exist, please try again.");
          }
  
          System.exit(0);
      } //END of Public Report ()
  
      public static void main(String[] args) throws Exception {
          new Report();
      } //End of Main
  
  } // End of Report Class
  </code></pre>