title: Convert String to File in Java
body: <p>I have code that asks the user to input a log file name so it knows what file it is to parse and sort. </p>
  
  <p>To be able to parse correctly, the <code>FileSource.parseXML</code> reads a variable type of <code>File</code>.  So, the input <code>String</code> needs to be converted to a <code>File</code>.  How would this be done?</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class Main
  {
      public static void main( String[] args )
      {
          FileSource src;
          File fd=null;
          int rc = 0;
          int count = 0;
          Record rec;
  
        //ask user what file to parse
        Scanner input = new Scanner(System.in);
        System.out.println("Enter file name:");
        String filename = input.nextLine();
  
        //TODO turn filename into fd
  
  
          //parse the records
          src = FileSource.parseXML( fd );
  
  
          //print out the number of records parsed
          rc = src.getRecordCount();
          System.out.println(rc);
  
  
          //print out all records. 
          for( int i = 0; i &lt; rc; i++)
          {
              rec = src.getRecord( i );
              System.out.println( rec.toString());
          } //end for loop
  
          return;
      }//end main method  
  
  }
  </code></pre>