October 1st, 2013, 06:25 PM
Converting Scanner class to a string- reading data from file
I have an assignment that I need to input a string (User), and then open a file, read from that file and then check if that file contains the String User. If it does, I also have to count how many times it occurs.
What I am getting stuck on is while it is reading the file, comparing it to User. I believe I need to covert the input file from scanner to string, but my question is how. I keep running into incompatible file types when I want to compile.
String STR2 = inputFile; //where I tried to get the input file to be a string.
}//end of static
}//end of class
October 1st, 2013, 07:34 PM
If inputFile is an instance of the Scanner class, you need to read the API doc for the Scanner class to see what method you want to use to read with.