title: Java - Reading A Double From A Text File
body: <p>I am trying to read through a file and determine how many numbers (separated by spaces) there are in the line.  If there is one number then that number is set as the radius of a circle and a circle object of that radius is created.  Similar actions are taken with two values (a rectangle) and three values (a triangle).  </p>
  
  <p>I believe that the error I am getting is occurring because of a problem with my code that takes numbers from the text file, which are strings, and converts them to doubles using <code>valueOf</code> on line 27 of my driver class.</p>
  
  <p><strong>The issue that I am having is when I run my driver program I get the following error:</strong> </p>
  
  <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: "in7.txt"
      at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
      at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
      at java.lang.Double.parseDouble(Double.java:538)
      at java.lang.Double.valueOf(Double.java:502)
      at Assignment7.main(Assignment7.java:27)
  </code></pre>
  
  <p><strong>Here is my driver class:</strong></p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  public class Assignment7
  {
     public static void main(String[] theArgs)
     {
        String filename = "in7.txt";
        int shapeNum;
        List&lt;Double&gt; shapeValues = new ArrayList&lt;Double&gt;();
        Shape myShape;
        double d;
        Scanner s = new Scanner(filename);
        try 
        {
           if (!s.hasNextLine())
           {
              throw new FileNotFoundException("No file was found!");
           }
           else
           {
              while (s.hasNextLine())
              {
                 shapeNum = 0;
                 Scanner s2 = new Scanner(s.nextLine());
                 while (s2.hasNext())
                 {
                    d = Double.valueOf(s2.next());
                    shapeNum++;
                    shapeValues.add(d);
                 }
                 if (shapeNum == 1)
                 {
                    myShape = new Circle(shapeValues.get(0));
                 }
                 else if (shapeNum == 2)
                 {
                    myShape = new Rectangle(shapeValues.get(0), 
                    shapeValues.get(1));
                 }
                 else
                 {
                    myShape = new Triangle(shapeValues.get(0),
                    shapeValues.get(1), shapeValues.get(2));
                 }
                 shapeValues.clear();
                 System.out.println(myShape);
              }
           }
           s.close();
        } 
        catch (FileNotFoundException e) 
        {
           System.out.println("File not found!" + e);
        }
     }
  }
  </code></pre>
  
  <p>I've been fiddling with this code for an hour and I cannot get it to run correctly.  Some help would be greatly appreciated.  Thanks!</p>