2 Replies - 2614 Views - Last Post: 21 April 2010 - 08:00 AM

#1 Saeedsys  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-December 08

how to search for a word in text files in j2me

Posted 04 April 2010 - 12:21 PM

Hi All dear i want to search for a word in a text files (.txt) in compare with inputed word
like dictionary .

Please Help me .

Thanks for all Replies>

Is This A Good Question/Topic? 0
  • +

Replies To: how to search for a word in text files in j2me

#2 Guest_jim2854*


Reputation:

Re: how to search for a word in text files in j2me

Posted 06 April 2010 - 06:49 PM

I'm going to assume that you know how to stream your text file into a string.

Create a string array

Then put your string into the string array by using: string = array.split(" ") - split on space

Find the number of string array elements and put that value in and integer we'll call x

Create an integer y = 0
Create a string = to the word you are looking for

Then do something like this:

while (y < x) {
If (( strcmp(string, array[y]) = 0);
break;
++y;
if (x == y)
break;
}

Now y is the string array element of your word. If x == y then you didn't find your word
Was This Post Helpful? 0

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10804
  • View blog
  • Posts: 40,277
  • Joined: 27-December 08

Re: how to search for a word in text files in j2me

Posted 21 April 2010 - 08:00 AM

Take a look at the java.io and javax.microedition.io packages. You will probably want to use an InputStream. In order to open an InputStream, you can use the Class getResourceAsStream(String path) method. Like so:
InputStream temp = getClass().getResourceAsStream("fileName.txt");



For more information on InputStream, check out the API:
http://java.sun.com/...nputStream.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1