Check the word available in text file using java
Hi,
I m beginner to java.
HOw i get a word in the text file.
I used this code, it is only display the all sentence which are available in the text file.
But , I need to check the particular word (if it is available in that text file)
package com.beryl;
import java.io.*;
class FileReadTest {
public static void main (String[] args) {
FileReadTest f = new FileReadTest();
f.readMyFile();
}
void readMyFile() {
BufferedReader dis =null;
String record = null;
int recCount = 0;
try {
File f = new File("E:/hello/abc.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis
= new BufferedReader(new InputStreamReader(bis));
while ( (record=dis.readLine()) != null ) {
recCount++;
System.out.println(recCount + ": " + record);
}
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error!" + e.getMessage());
} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
try {
dis.close();
} catch (IOException ioe) {
}
}
}
}
}
Thanks & Regards,
kumar

