Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Macthing string in text file.

Thread view: 
ruds - 10 Sep 2006 05:16 GMT
Hello,
Can someone tell me how do i find a particular string in the text file.
Suppose i have a text file and i want to check if a word say 'computer'
is present or not in the file ,so how do i go about it?
hiwa - 10 Sep 2006 05:23 GMT
ruds のメッセージ:

> Hello,
> Can someone tell me how do i find a particular string in the text file.
> Suppose i have a text file and i want to check if a word say 'computer'
> is present or not in the file ,so how do i go about it?
Read the API documentation for the java.lang.String class.
Read every line of your text.
Apply one of String metods to each line to chack word matching.
The indexOf() method will be handy.
Manish Pandit - 10 Sep 2006 06:14 GMT
Hi,

Use the java.io.File API to open up the file, and then use the
java.io.BufferedReader API to read it line by line. For every line,
based on case sensitivity, you can either do a
line.toUpperCase().indexOf("computer".toUpperCase()) > 1 or
line.indexOf("computer") > 1.

-cheers,
Manish

> Hello,
> Can someone tell me how do i find a particular string in the text file.
> Suppose i have a text file and i want to check if a word say 'computer'
> is present or not in the file ,so how do i go about it?
hiwa - 10 Sep 2006 07:15 GMT
Manish Pandit のメッセージ:

> Hi,
>
[quoted text clipped - 11 lines]
> > Suppose i have a text file and i want to check if a word say 'computer'
> > is present or not in the file ,so how do i go about it?

> Use the java.io.File API to open up the file
No. You can't do that. Simply create a BufferedReader passing a
FileReader(yourfile) to its constructor.
ruds - 10 Sep 2006 07:22 GMT
Manish Pandit - 11 Sep 2006 01:51 GMT
> > Use the java.io.File API to open up the file
> No. You can't do that. Simply create a BufferedReader passing a
> FileReader(yourfile) to its constructor.

Last I checked, this is how it works. Anything I missed?

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.