Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   hi (http://www.velocityreviews.com/forums/t390502-hi.html)

kavithadayalanvit@gmail.com 01-31-2007 06:53 AM

hi
 
i want to search a particular word in the file using java.
can u give any specific link for this

regards
kavitha


Luc The Perverse 01-31-2007 07:53 AM

Re: hi
 
<kavithadayalanvit@gmail.com> wrote in message
news:1170226439.643463.93880@j27g2000cwj.googlegro ups.com...
>i want to search a particular word in the file using java.
> can u give any specific link for this
>
> regards
> kavitha
>


Read the file

Check the input for the word

If the word is found then display something

Repeat.

. . . .

Maybe it would be better if you showed us what you had tried, specifically
what is not working and we can work from there.

--
LTP

:)



Lab.Bhattacharjee@gmail.com 01-31-2007 12:11 PM

Re: hi
 
Hi kavitha,
u can try out the following code , it allows wild cards ,but is case
sensitive.Please tell me if u need that too??
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RnD {

public static void main(String[] args) {
Pattern pattern = Pattern.compile("SAXELBY");
BufferedReader reader = null;
try {
int lineNumber=0;
reader =
new BufferedReader(
new FileReader("C:\\00000001.txt"));
while (true) {
lineNumber++;
String curline = reader.readLine();
if (curline == null) {
break;
}
Matcher matcher = pattern.matcher(curline);
while (matcher.find()) {
System.out.println("at "+lineNumber+" "+
matcher.group()
+ " start="
+ matcher.start()
+ " end= "
+ matcher.end());
}
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}

}
}

thanks
lab


Lew 01-31-2007 12:55 PM

Re: hi
 
Lab.Bhattacharjee@gmail.com wrote:
> Hi kavitha,
> u can try out the following code , it allows wild cards ,but is case
> sensitive.Please tell me if u need that too??


The word is "you", not "u".

The trouble with doing someone's homework for them is that you deprive them of
an education. That's a big waste of their tuition.

> import java.io.BufferedReader;
> import java.io.FileNotFoundException;
> import java.io.FileReader;
> import java.io.IOException;
> import java.util.regex.Matcher;
> import java.util.regex.Pattern;
>
> public class RnD {
>
> public static void main(String[] args) {


Please do not embed TABs in Usenet posts.

> Pattern pattern = Pattern.compile("SAXELBY");


What is this regex? How did you come up with it? There was no indication in
the OP for this.

> BufferedReader reader = null;
> try {
> int lineNumber=0;
> reader =
> new BufferedReader(
> new FileReader("C:\\00000001.txt"));


Hard-coded strings. Tsk, tsk. Where did you come up with it? There was no
indication in the OP for this.

> while (true) {


To depend on exceptions as flow control is a bad practice.

> lineNumber++;
> String curline = reader.readLine();
> if (curline == null) {
> break;
> }
> Matcher matcher = pattern.matcher(curline);
> while (matcher.find()) {
> System.out.println("at "+lineNumber+" "+
> matcher.group()
> + " start="
> + matcher.start()
> + " end= "
> + matcher.end());
> }
> }
>
> } catch (FileNotFoundException e) {
> e.printStackTrace();


Ooh, you ignore the exception and move on. This is good for examples, bad in
practice.

This is also a good place to introduce logging statements.

> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> if (reader != null) {
> try {
> reader.close();
> } catch (IOException e1) {
> e1.printStackTrace();


Those darn TABs.

> }
> }
> }
>
> }
> }


- Lew

Oliver Wong 01-31-2007 07:13 PM

Re: hi
 
<kavithadayalanvit@gmail.com> wrote in message
news:1170226439.643463.93880@j27g2000cwj.googlegro ups.com...
>i want to search a particular word in the file using java.
> can u give any specific link for this


http://www.google.ca/search?q=search...ile+using+java

- Oliver



Randolf Richardson 02-02-2007 04:26 AM

Java needs "goto" (was Re: hi)
 
On Wed, 31 Jan 2007 04:55:35 -0800, Lew <lew@nowhere.com> wrote:
> Lab.Bhattacharjee@gmail.com wrote:

[sNip]
>> while (true) {

>
> To depend on exceptions as flow control is a bad practice.

[sNip]

This typically occurs because the reserved word "goto" isn't
implemented. There are situations where "goto" would be very useful, such
as:

0. An alternative to "break label" since label is currently limited in
where it can be located (such code could be easier to read)

1. The ability to share code between methods within a class, which all
end with the same functionality (this could be more efficient than calling
another method; javac would need to generate errors such as attempts to
access variables that belong to different methods, return type mismatches,
etc.)

I do agree with your view that infinite loops that depend on exceptions
are a bad practice. Using conditionals to trigger a "break" would also be
better handled by making that the focus of the loop -- and if they need to
compare afterwards, then "do { ... } while (condition);" can certainly
solve that problem.

--
Randolf Richardson - kingpin+nntp@lumbercartel.ca
The Lumber Cartel, local 42 (Canadian branch)
http://www.lumbercartel.ca/

kavithadayalanvit@gmail.com 02-02-2007 09:04 AM

Re: hi
 
On Jan 31, 5:11 pm, "Lab.Bhattachar...@gmail.com"
<Lab.Bhattachar...@gmail.com> wrote:
> Hi kavitha,
> u can try out the following code , it allows wild cards ,but is case
> sensitive.Please tell me if u need that too??
> import java.io.BufferedReader;
> import java.io.FileNotFoundException;
> import java.io.FileReader;
> import java.io.IOException;
> import java.util.regex.Matcher;
> import java.util.regex.Pattern;
>
> public class RnD {
>
> public static void main(String[] args) {
> Pattern pattern = Pattern.compile("SAXELBY");
> BufferedReader reader = null;
> try {
> int lineNumber=0;
> reader =
> new BufferedReader(
> new FileReader("C:\\00000001.txt"));
> while (true) {
> lineNumber++;
> String curline = reader.readLine();
> if (curline == null) {
> break;
> }
> Matcher matcher = pattern.matcher(curline);
> while (matcher.find()) {
> System.out.println("at "+lineNumber+" "+
> matcher.group()
> + " start="
> + matcher.start()
> + " end= "
> + matcher.end());
> }
> }
>
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> if (reader != null) {
> try {
> reader.close();
> } catch (IOException e1) {
> e1.printStackTrace();
> }
> }
> }
>
> }
>
> }
>
> thanks
> lab


hi

thanks for ur reply. it will also be helpful if u sent the coding
which u have asked me .

waiting for ur reply

regards
D.kavitha


Gordon Beaton 02-02-2007 12:57 PM

Re: hi
 
On Wed, 31 Jan 2007 07:55:35 -0500, Lew wrote:
> Lab.Bhattacharjee@gmail.com wrote:
>> while (true) {

>
> To depend on exceptions as flow control is a bad practice.


That may be, but he hasn't done so in this case. The loop condition
here is (curline != null), even though the test doesn't occur until a
few lines further down.

BTW exceptions *are* a form of flow control, whether you like them or
not.

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e

Michael Rauscher 02-02-2007 01:33 PM

Re: hi
 
Gordon Beaton schrieb:
> On Wed, 31 Jan 2007 07:55:35 -0500, Lew wrote:
>> Lab.Bhattacharjee@gmail.com wrote:
>>> while (true) {

>> To depend on exceptions as flow control is a bad practice.

>

....
>
> BTW exceptions *are* a form of flow control, whether you like them or
> not.


That may be but he didn't tell us if they are or are not a form of
control flow.

To my understanding the key was not to *depend* on exceptions as flow
control or IOW not to (mis)use the exceptional flow to control the main
flow which is right although not always possible.

Bye
Michael

Lew 02-02-2007 03:14 PM

Re: hi
 
kavithadayalanvit@gmail.com wrote:
> thanks for ur reply. it will also be helpful if u sent the coding
> which u have asked me .


Juat a word of friendly advice: Your posts will seem much more professional,
and you will be in better practice for workplace communication, if you make a
habit of using more (not completely) formal written English, in particular if
you avoid so-called "l33t-speak" or "txt-English", comprising abbreviations
like "u" for "you", informal or missing punctuation and capitalization, etc.

The trouble is that the use of the abbreviated idiom conveys an impression of
unprofessionalism and a low skill set. This may be the view of yourself that
you wish to convey, but I fail to see how that can help you.

You will impress more, and likely get more expert responses, if you take the
care and trouble to follow conventional English syntax and orthography
(barring the odd misplet word - this forum isn't completely formal).

Just a suggestion designed to help you.

- Lew


All times are GMT. The time now is 06:31 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.