Bookmark Topic Watch Topic
  • New Topic

match the word from text file

 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi all,

i have an input like this in the text file

located 1
biosphere 2
reserve 3


in this i want to find if the text file has the word located. It should match the word and display the result as 1. How to do like that ? Help me...

 
Komal Arora
Ranch Hand
Posts: 91
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
You can do the following:
1) you input the text file, use readLine() to read the lines in the text file one by one.
2) after that you can use stringTokenizer class. You get two tokens at each line.
3) Store the tokens in a data structure. for eg tree map: TreeMap<String, Integer> = new TreeMap<String, Integer>();
4) once you have all the values in the tree map, you can just get the value for a particular string. The map would have entires like: Located, 1 ; biosphere 2 and so on.
So for Located you will get the value 1.

I did this for my project. I had a text file with some numerical values which were required for some calculation. So i read the file, used StringTokenizer to get the tokens and stored them in the tree map.

 
Winston Gutkowski
Bartender
Pie
Posts: 10103
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
deepika deepi wrote: i have an input like this in the text file

Deepika, this is a duplicate of this thread. Please don't double-post.

Locking this one.

Winston
 
    Bookmark Topic Watch Topic
  • New Topic