Read the content of the text file: http://www.javapractices.com/topic/TopicAction.do?Id=42
And after that just use the textData.contains(user_input);
method, where textData
is the data read from the file, and the user_input
is the string that is searched by the user
UPDATE
public static StringBuilder readFile(String path)
{
// Assumes that a file article.rss is available on the SD card
File file = new File(path);
StringBuilder builder = new StringBuilder();
if (!file.exists()) {
throw new RuntimeException("File not found");
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return builder;
}
This method returns the StringBuilder created from the data you have read from the text file given as parameter.
You can see if the user input string is in the file like this:
int index = readFile(filePath).indexOf(user_input);
if ( index > -1 )
System.out.println("exists");