I'm working on a program where I'm reading a file and I have to count the number of entries in the file. Each entry takes up a different number of lines, but each entry is also separated by a '#'. I'm wanting to read through the file and count the number of '#' marks first before I do anything, but I can't figure out how exactly to do it.
Here is what I have so far, and I keep getting an "incompatible types" error because i'm checking for characters and apparently # isn't a character, or i'm just doing something totally wrong. Is there some method I need to be calling to do this or what? I'm stuck, lol, HELP!!!
public static int scanFile(String test)throws IOException
{
char mark = "#";
int count=0;
Scanner fin = new Scanner(new File(test));
while(fin.hasNext())
{
String line = fin.nextLine();
for(int x=0; x<line.length(); x++)
{
if(line.charAt(x) == mark)
count ++;
}//end for
}//end while
return count;
}//end scanFile
I can make it work just fine if I count the number of lines in the file, just not for counting the #... I'm not really looking for an ANSWER, just maybe a tip, or point out something I'm overlooking.