Seaching word in text file using JAVA.  
Author Message
pianke2





PostPosted: 2005-3-3 21:00:00 Top

java-programmer, Seaching word in text file using JAVA. Hello,

I have a problem on seaching word in text file using JAVA.
Below are the sample code i have written for searching word honda,
1990 and imran.I also want to save word honda in static string name
classtring. For first line i use this java code to save word honda in
classtring and its working well. I have a problem to save second line
1990 and imran.
The technique i use is searching until "=" and save word after "=".Can
anyone give the idea and java code.

Thank you...

------------java code ------------------

content = f.readLine();

// find class name
StringTokenizer s = new StringTokenizer (content,"=");
while (s.hasMoreTokens())
{
String string_val = s.nextToken();
if (string_val.trim().equals("classname".trim()))
{
classString=s.nextToken();
}
}

------- data text file -------------

name_car = honda
year = 1990
owner = imran
 
Malte





PostPosted: 2005-3-3 22:21:00 Top

java-programmer >> Seaching word in text file using JAVA. imran wrote:
> Hello,
>
> I have a problem on seaching word in text file using JAVA.
> Below are the sample code i have written for searching word honda,
> 1990 and imran.I also want to save word honda in static string name
> classtring. For first line i use this java code to save word honda in
> classtring and its working well. I have a problem to save second line
> 1990 and imran.
> The technique i use is searching until "=" and save word after "=".Can
> anyone give the idea and java code.
>
> Thank you...
>
> ------------java code ------------------
>
> content = f.readLine();
>
> // find class name
> StringTokenizer s = new StringTokenizer (content,"=");
> while (s.hasMoreTokens())
> {
> String string_val = s.nextToken();
> if (string_val.trim().equals("classname".trim()))
> {
> classString=s.nextToken();
> }
> }
>
> ------- data text file -------------
>
> name_car = honda
> year = 1990
> owner = imran

As suggested to your previous post along the same topic: try String's
split method, then use trim() on the results.
 
Rhino





PostPosted: 2005-3-3 22:23:00 Top

java-programmer >> Seaching word in text file using JAVA.
"imran" <email***@***.com> wrote in message
news:email***@***.com...
> Hello,
>
> I have a problem on seaching word in text file using JAVA.
> Below are the sample code i have written for searching word honda,
> 1990 and imran.I also want to save word honda in static string name
> classtring. For first line i use this java code to save word honda in
> classtring and its working well. I have a problem to save second line
> 1990 and imran.
> The technique i use is searching until "=" and save word after "=".Can
> anyone give the idea and java code.
>
The best technique to use probably depends on what you are trying to do with
the data that you find. But I'm not very clear about that.

Are you simply trying to determine if 'honda', 'imran', and '1990' exist in
the file? In other words, would a one word report with either the word 'yes'
or 'no' satisfy your requirements? Or do you need to know which line and
column each word begins in? Or do you need to actually copy each word to
another file? And so on. There are many possible things you can do with this
data. I'm not certain why you are saving "imran"; is it just so that you can
keep track of what is happening yourself or is it because you need to store
it for use in some other way.

Also, if this is a homework assignment, I hope you're not expecting the
people on this group to do your homework for you. We don't mind answering
the occasional question or giving the occasional hint but we aren't a
homework completion service....

Rhino