Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding end of line while using Scanner class

Status
Not open for further replies.

pson41

MIS
Feb 20, 2005
2
US
I have a project I'm working on that scans through a file one word at a time. I am looking for a specific word in each line and if I don't find it I am suppose to count that line as not having the word. I don't want to have to create a tokenizer so if someone knows how to search through the words in a line and still recognize the end of a line in the scanner class I would greatly appreciate your help.
 
You don't need to use the Scanner class to do this.
This is probably the quickest way to do it :

Code:
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("myfile.txt"));
String line = "";
while ((line = br.readLine()) != null) {
	if (line.indexOf(" myword ") != -1) {
		System.out.println("word is in the line");
	}
}

br.close();


--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks, I'm still learning java and thought the scanner class was simpler to implement. It just doesn't have the functionallity that I need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top