you are trying to count the number of occurrences of a character in a file. This requires you to read the file from disk, for this task you have to use a Reader. A PrintWriter class is a writer so you are not going to be able to use it here. If your code required you to read the result into a file then thats where Writer (PrintWriter) would come in.