search - Searching a text file in java and Listing the results -


i've searched around ideas on how go this, , far nothing's turned up.

i need search text file via keywords entered in jtextfield , present search results user in array of columns, how google it. text file has lot of content, 22,000 lines of text. want able sift through lines not containing words specified in jtextfield , present lines containing @ least 1 of words in jtextfield in rows of search results, each row being line text file.

anyone has ideas on how go this? appreciate kind of help. thank in advance

you can read file line line , search in every line keywords. if find one, store line in array.

but first split text box string whitespaces , create array:

string[]          keywords = yourtextboxstring.split(" "); arraylist<string> results  = new arraylist<string>();  

reading file line line:

void readfilelinebyline(file file) {     bufferedreader br = new bufferedreader(new filereader(file));     string         line;      while ((line = br.readline()) != null) {        processoneline(line);     }      br.close(); } 

processing line:

void processoneline(string line) {     (string currentkey : keywords) {         if (line.contains(currentkey) {             results.add(line);             break;         }     } } 

i have not testst this, should overview on how can this.

if need more speed, can use regularexpression search keywords don't need loop.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -