Java - search/find a word in a text file 1 Answer(s) 3 years and 3 months ago
Posted in : Java Beginners
Hello,
I would like to know how to find from a list of lets say 10 but could be more, .txt files, how to search them for a word. The word will be PASS or it can be FAIL.
If PASS I want to do nothing, if FAIL, I want to record in 1 master output file, the name of the file that has FAIL in it.
Please help.
Thank you. Manan
View Answers
March 9, 2010 at 11:32 AM
Hi Friend,
Here is the studentRecord.txt:
1 A 90 PASS 2 B 30 FAIL 3 C 80 PASS 4 D 99 PASS 5 E 85 PASS 6 F 25 FAIL
Try the following code:
import java.io.*; import java.util.*;
public class SearchWord{ public static void main(String[]args) throws Exception{ Scanner input=new Scanner(System.in); System.out.print("Enter word to find: "); String word=input.next(); if(word.equals("FAIL")){ File f = new File("studentRecord.txt"); BufferedReader freader = new BufferedReader(new FileReader(f)); String s; while ((s = freader.readLine()) != null) {
String[] st = s.split(" "); String id = st[0]; String name = st[1]; String marks = st[2]; String result = st[3]; if (result.equals(word)) { File file = new File("result.txt");
FileWriter fstream = new FileWriter(file,true); BufferedWriter out = new BufferedWriter(fstream); out.write(id+" "+name+" "+marks); out.newLine(); out.close(); } } } } }
Java search word from text file Javasearchword from textfile
In this tutorial, you will learn how to search a word from textfile and
display data related to that word. Here, we have created a textfile student.txt
which consists of id, name and marks of few
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 Wordfile. To save in our desktop computer. Solve my problem
Search word from text file using Java
How to Searchword from textfile using Java
In this section, we are going to search a word from the textfile. For this, we have created a swing button... the user typed his/her name, it will check the name in the textfile. To check
Scanning a word in a TEXT document......
Scanning a word in a TEXT document...... Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVAword is present means
Scanning a word in a TEXT document......
Scanning a word in a TEXT document...... Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVAword is present means
String file in to word file in java
String file in to wordfile in java how to convert a String format wordfile into Ms Wordfile using java? please can anyone of you help me
Convert Text To Word
;
In this
example, You will learn how to convert text to wordfile. Here, we are
going to discuss about the conversion of text to wordfile.
Core... file. This program converts the text to wordfile by using
FileOutputStream("
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... ((devstr = br.readLine()) != null) {
String text = devstr;
String text1
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 TextFile on JButton Click in java Hi Friend,
Try the following code:
import java.io.*;
import java.util.*;
import javax.swing.
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 textfile in a local drive, and count
the frequency of each word in the textfile or you can say count the number or
occurrence of each word
Count instances of each word
Count instances of each word I am working on a Java Project that reads a textfile from the command line and outputs an alphabetical listing... going wrong...could anyone help to put me in the right direction?
From my textfile
Collections Exercise 4 - Word Translator Java: Collections Exercise 4 - Word Translator
333.
leftnewads2.shtml..., a simple textfile might have the following
structure for showing the English...: An online dictionary is needed. The user will enter
a word and the program
Reading a text file in java
in java.io.* package for reading and writing to a file in Java.
To learn more about reading textfile in Java see the tutorial Read File in Java.
Thanks...Reading a textfile in java What is the code for Reading a textfile
How to format text file? - Java Beginners
How to format textfile? I want the answer for following Query
***(Java code)
How to open,read and format textfile(notepad) or MS-word.../example/java/io/java-read-file-line-by-line.shtml
Thanks
Java Word Processor JavaWord Processor Problem: Design and implement a class called WordProcessor. This class is
used to:
? hold a line of text that can be manipulated in various ways
? perform various manipulations and modify the text
Java Word Occurrence Example
)
{
System.out.println(e);
}
}
}
}
bipul.txt
Contents of the textfile is as follows
Java...JavaWord Occurrence Example
In this example we will discuss about the how... can count the occurrences of each word
in a file. In this example we will use
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 will provide an example that will read the document file using POI library in java
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 will provide an example that will read the document file using POI library in java
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 will provide an example that will read the document file using POI library in java
create , edit MS WORD like document file using Java Swing - Swing AWT
create , edit MS WORD like document file using Java Swing In my program I have JTextArea. Text in JTextArea can be set to
selected font, font style etc. I want this text in JTextArea to
be saved to MS WORD like
java number to word - Java Beginners java number to word Can somebody please fix this to come out with the word, not the number 23?
import java.util.Scanner;
public class...
{
//-----------------------------------------------------------------
// Pulls integers from a string to form a word
print only Form Fillup Contents through Text File - Java Beginners
print only Form Fillup Contents through TextFile Hello Sir ,I have Designed Employee Details Form using java swing components Now i want to print... it with word means when i click on print then contents which is filled
java word counting - Java Beginners javaword counting Hi I want a code in java that replaces a word with another when its occurred independently and ignores the case of the text... but this will change all the occurrence even if its part of another word the run
convert word document to pdf
convert word document to pdf Hi,
Could you please help me write a java code that converts the word docuemnt into PDF?
I have to save the generated...?
import officetools.OfficeFile;
fis = new FileInputStream(new File("test.doc
how to update the text file?
how to update the textfile? if my textfile contains a string and integer in each line say,:
aaa 200
bbb 500
ccc 400
i need a java code to update the integer value if my input String matches with the string in file.
please
save text file - Java Beginners
save text file hi
i have just start programming in java.please guide me if i want to read a textfile in java.then the textfile is save in which directory
Read text File
Read text File Hi,How can I get line and keep in a String in Java
writing a text into text file at particular line number
writing a text into textfile at particular line number Hi,
thanks for quick response, I want to insert text at some particular line number..
after line number four my text will display in textfile using java program
how to update the text file?
how to update the textfile? my textfile with name list.txt:
Rice... in my textfile, if the item i entered matches with item in text file.how can i... 150
....
....20 lines.
java code:
import java.io.*;
import java.util.*;
class
Adding a text file - Java Beginners
Adding a text file Hello,
I need a program that will search a textfile of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings
Problem reading word file
Problem reading word file Deepak you provide me code for extarcting equation from a wordfile and also to write in a word file.But when I again want to read preveously created wordfile(created by your code) it gives an error
writing a text into text file at particular line number
writing a text into textfile at particular line number Hi,
thanks for quick response, I want to insert text at some particular line number..
after line number four my text will display in textfile using java program
 
writing a text into text file at particular line number
writing a text into textfile at particular line number Hi,
thanks for quick response, I want to insert text at some particular line number..
after line number four my text will display in textfile using java program
 
Example - Replace word Java: Example - Replace word
Problem:
Write a method to replaces all occurences a word in a string with another word.
Assume the method signature is
static String replaceWord(String original,
String find
create MS Word in Java - Java Beginners
which creates MS Word in Java...create MS Word in Java Hi,
Could any one please post the code which creates the word document having different paragraphs and two tables.
i have
Java word extraction program. - Java Beginners Javaword extraction program. Need to code a public class named WordExtractor that contains a main method. Prompt the user to enter a line of text and read it in using a Scanner object. The line of text should follow the prompt
Search and return lines of text file Search and return lines of text file I wrote the following code, that found lines of txt file with contains certain word, but it returns only... with the word! )
Where is the problem?!
Thank U :)
"import java.io.*;
public
pdf to text
pdf to text how to covert pdf file (which contain table and text) into word or excel file using itext api
Java search text file Javasearchtextfile
In this tutorial, you will learn how to search a text... the name of a textfile to
search for. If the name does not have a .txt extension, display an error
message. Then search the file in the current directory
JTextArea to Word Document
:
On clicking the button 'Save', the text will get saved in the wordfile.
You... that enable us to
perform read, write operations with ms wordfile. Here we are going to write the data into word document file through a swing component.
You can
Creating MS Word document in java - Struts
Creating MS Word document in java I have one template in MS Word which has some content. Now i want to read this doc file and wants to add some content and also i need to set header and footer in doc file. That is, reading