This is some code that counts how many B’s there are in the words file.
package readfromfile;</pre> import java.io.*; public class ReadFromFile { <pre>public static void main(String[] args) { String s = ""; int i = 0; int count = 0; try { BufferedReader reader = new BufferedReader(new FileReader("c:\\words.txt")); i = reader.read(); while (i != -1){ s = new Character((char)i).toString(); // This converts the int to a String if (s.equals("B")){ count = count + 1; } i = reader.read(); } reader.close(); System.out.println("The file contains " + count + " B characters."); } catch (Exception e) { e.printStackTrace(); } } }