title: Compilation error: variable might not have been initialized
body: <p>I'm trying to create a method that adds to a variable for each character inside a file. If the file was:</p>
  
  <pre><code>abcd
  abc
  ab
  </code></pre>
  
  <p>then after the function ran the variable it would return would be equal to 9.</p>
  
  <p>Here's the code I have so far:</p>
  
  <pre><code>public static double getRow(String filename) {
     double size = 0;
     File f;
     Scanner infile;
     try{
        f = new File(filename);
        infile = new Scanner(f);
     }
     catch (IOException e){
         System.out.println("Error opening the file");
         //System.exit(0); not good
     }
     while(infile.hasNext()) {
         size++;
     }
     infile.close();
     return size;
  
  }
  </code></pre>
  
  <p>But I keep getting that <code>infile</code> has not been initialized. I'm not sure how to get the solution I want.</p>