Home Answers Viewqa Java-Beginners how to match the key word from a text file

Deepika
how to match the key word from a text file
Posted in : Java Beginners

p>Hi all, I have the code to match the key word and from the text. I have input like this reader.txt

Guindy National Park is located in Chennai , South India , one of the last remnants of tropical dry evergreen forest of the Coromandel Coast , Guindy Park was originally a game reserve.

and 2.txt is located biosphere reserve

I am getting an output like this now. Number of times Tim is: located Number of times Tim is: serve

the expected output is Number of times Tim is: located

code is as follows
**import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Classnew
{
public static String getnew()
{
String data2 = "";
try {
String devstr;
while ((devstr = br.readLine()) != null) {
System.out.println(devstr);
data2+=devstr+"\n";
}
} catch (IOException e) {
}
return data2;
}
}
public class Findwordphrase {
public static void main(String[] args) {
Classnew classnew = new Classnew();
String data2 =classnew.getnew();
System.out.println("Data of Class2(keyWrd): " + data2);
try {
String devstr;
while ((devstr = br.readLine()) != null) {
String text = devstr;
String text1 = text.replaceAll("  ","").replaceAll("   "," ");
System.out.println(text1);
String[] words = text1.split(" ");
for (String word : words)
{
String regex1 = "\\b"+data2+"\\b";
Pattern pattern1 = Pattern.compile(regex1);
Matcher matcher1 = pattern1.matcher(word);
String val = null;
while (matcher1.find()) {
val = matcher1.group();
System.out.println("Number of times Tim is: " +val );
}
}
}
} catch (IOException e) {
}//try catch ends
}
}**

If i give the input like this String regex1 = "\blocated|reserve|biosphere\b";

instead of this i am getting the result. I don't want to hard code the string. instead i want to get the value from the called file and get the result. String regex1 = "\b"+data2+"\b";

i am missing some part to get the correct output and not able to find that. If any one could find my mistake help me. please...

Related Pages:
how to match the key word from a text file
how to match the key word from a text file  p>Hi all, I have the code to match the key word and from the text. I have input like this reader.txt... want to get the value from the called file and get the result. String regex1
Java search word from text file
Java search word from text file In this tutorial, you will learn how to search a word from text file and display data related to that word. Here, we have created a text file student.txt which consists of id, name and marks of few
stop word removal from text file
stop word removal from text file  i need java source code for stop word removal from a text file
Search word from text file using Java
How to Search word from text file using Java In this section, we are going to search a word from the text file. For this, we have created a swing button... from the text file. Here is the code: import java.io.*; import
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
Java - search/find a word in a text file - Java Beginners
Java - search/find a word in a text file  Hello, I would like to know how to find from a list of lets say 10 but could be more, .txt files, how...]; String result = st[3]; if (result.equals(word)) { File file = new
Logic Match Tag (<logic:match >...</logic:match >)
:match &gt; </h5>  Result : entered text contains "... Logic Match Tag (<logic:match >...</logic:match >) ...; match tag - We use this tag to evaluate the contents contained
How to Open Text or Word File on JButton Click in Java - Java Beginners
How to Open Text or Word File on JButton Click in Java  How to Open Text or Word File on JButton Click in Java
Convert Text To Word
; In this example, You will learn how to convert text to word file. Here, we are going to discuss about the conversion of text to word file.  Core... file. This program converts the text to word file by using FileOutputStream("
Count repetitions of every word from an input file
Count repetitions of every word from an input file  Hello..i got to know how can i count the repetitions of every word present in a specific input file?For suppose if i have a url log file which have time,url's,ip address etc
How to remove paragraph from ms word
How to remove paragraph from ms word  Hi! I am using MS Word to edit my text but somehow i get paragraph sign on every line of my text. So, can any one please tell me how to remove paragraph from ms word?   CTRL+SHIFT+8
Counting specific word occurences in a file
Counting specific word occurences in a file  Hello I have a log file from the proxy which consists all the browsing history with date,time,url,ip... name and need to count how many times those sites(url's) are being visited
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
Read the Key-Value of Property File in Java
Read the Key-Value of Property File in Java  ... the key-value of properties files in Java. The properties file provides...; it takes the key of the properties file after that shows the appropriate key-value
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
Compare two word file
Compare two word file  How to compare two word file using Java
Problem reading word file  Deepak you provide me code for extarcting equation from a word file and also to write in a word file.But when I again want to read preveously created word file(created by your code) it gives an error
String file in to word file in java
String file in to word file in java  how to convert a String format word file into Ms Word file using java? please can anyone of you help me
Final Key Word in Java
.style1 { text-align: center; } Final key word in java In java final is a key word used in several different contexts. It is used before a variable, method, and classes so that they cannot be changed latter. Final Variables
Reading text from image file - Java Beginners
How to handle enter key in javascript
How to handle enter key in javascript  Can any one tell me how... to submit the form even if user hits the enter key from keyboard instead... key get hit from keyboard
Java Word Occurrence Example
will demonstrate you about how to count occurrences of each word in a file. In this example...Java Word Occurrence Example In this example we will discuss about the how many times words are repeated in a file. This example explains you that how you
Read Text file from Javascript - JSP-Servlet
Read Text file from Javascript  plz send the code How to Retrieve the data from .txt file thru Javascript? And how to find the perticular words in that file
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Java Count word occurrence and export it to excel file
Java Count word occurrence and export it to excel file Here is an example of scanning a text file in a local drive, and count the frequency of each word in the text file or you can say count the number or occurrence of each word
How to make text effect
Tool (T key) and write any word in the file. Effects: Go to Layer Menu >... How to make text effect We can make too many text effect in the photoshop, this text effect is one of them. Let's start... New File: Take a new
binary search tree from text file
binary search tree from text file  How so I go about constructing a binary search tree from a text file, which has letters and numbers, which must be sorted and printed in ascending order. E.g. Text file contents 3 apples pears
Count characters from text file in Java
Count characters from text file in Java  At the "Count chracters fro... is a java code that count the occurrence of each character from text file. import... the directory of the text file ("C:\text.txt"). I use Eclipse to run this code. I
Open Text or Word Document on JButton Click in Java - Java Beginners
Open Text or Word Document on JButton Click in Java  How to open Word document or Text File on JButton Click in java  Hi Friend, Try the following code: import java.io.*; import java.util.*; import javax.swing.
Character from text file - Java Beginners
Character from text file  Write a program that reads characters from a text file. Your program will count how many time each character appear in the text. Assume that the letters are case-sensitive. Example output
How to design key, design key, key
How to design key       It has been made easy now to design a key by this example, just... File: Create a new file and take appropriate size of the file. Pen Tool
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
How to make a list from file text in J2ME - Java Beginners
How to make a list from file text in J2ME  I was trying to make a method that read file from text and make a list of it, I have tried ReadHelpText...) { } return null; } kamus.txt file contains: iconSebuah lambang kecil berupa gambar
How to extract a specific line from a text file? - IoC
How to extract a specific line from a text file?  Hi all, i'm trying to write a code that return a specific line from a text file. so my first...° 100 to 120 for example. My Text file contain numbers and words. How i have
Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words
Retrieve a list of words from a website and show a word count plus a specified... the document text from the web (provided by utility class) 2.Filter the desired "words" form the document, and one by one, store each word as a key into a Map<
how to create text file from jsp and provide downlode option
how to create text file from jsp and provide downlode option  HI... file so that pepole can downlode that text file or may be some other file formate... of this page in text file and also downlode option of this text field thanks
Count instances of each word
that reads a text file from the command line and outputs an alphabetical listing... going wrong...could anyone help to put me in the right direction? From my text file, my output should be this: 1 a 1 am 1 computes 2 file 1 i 1 in 1 is 2 my 1
upload and retrieve a word document - JSP-Servlet
unable to retrieve the word document from database. I am writing the code... bigint(20) NOT NULL auto_increment, file_data text, file_date` datetime...upload and retrieve a word document  Hi, I have a problem
How to make an image full text.
How to make an image full text.       Feel relief from color text, it's not tuff to design... option to make an image full text so follow now. Open a file: First open
Regular Expressions
This Example describe the way to print the matching word from the file... expression This Example describe the way to calculate the Repeating word from... to find a given word from the String and also the no of times the word exists
How to format text file? - Java Beginners
How to format text file?  I want the answer for following Query ***(Java code) How to open,read and format text file(notepad) or MS-word... String getContents(File aFile) { StringBuilder contents = new StringBuilder
JTextArea to Word Document
: On clicking the button 'Save', the text will get saved in the word file. You... that enable us to perform read, write operations with ms word file. Here we are going to write the data into word document file through a swing component. You can
THE key Word WHERE in SQL, SQL Tutorial
; SELECT column FROM table WHERE column operator value... a WHERE  to the SELECT statement:  SELECT * FROM
How to read text file in Servlets
How to read text file in Servlets       This section illustrates you how to read text file in servlets. In this example we will use the input stream to read the text
convert data from pdf to text file - Java Beginners
convert data from pdf to text file   how to read the data from pdf file and put it into text file(.txt
How to copy text from a gif image
How to copy text from a gif image  I have some gif images that containing some important text. i want to have that text in my notepad file. i have.... so, please tell me how can i copy that text to my notepad. i am using ubuntu
How to make a cloudy text, cloudy text, text
How to make a cloudy text      ... of you text as I have done here. Take another new file for text. Take a New File: Now take a new file to write text as I have taken here. Setting of the Text: We