I need to count the number of times a substring occurs in a file using scanner and JFIleChooser
<p>I am trying to learn Java and I want to know how I can count the number of times a substring occurs in a chosen text file and have it output to the console. For example say I used <code>JFileChooser</code> to grab a text file from my computer and I wanted to know how many times the substring "if" or "ot" occurred in the file. Any help would be appreciated!</p>

<pre><code>import java.util.Scanner;
import javax.swing.JFileChooser;

public class FileReader {
    public static void main(String[] args) {
        int count = 0;
        JFileChooser chooser = new JFileChooser();
        Scanner in = new Scanner(/* How do I get the file? */);
        { // file read
            while (in.hasNext()) {
                count++;
                in.next();
            }
            System.out.println("The word count is " + count);
        }
    }
}
</code></pre>