java - String has access to entire text file -


i working on java project loosely simulates search engine converting gettysburg address text file linear-linked list of word objects contain string of word , line position. compare these against hash table of ignorable words , insert considerable words binary search tree number of appearances recorded if duplicates occur.

i have hashing function , of tree-adding parts down having issue can't seem figure out regarding input:

when reading gettysburg address using bufferedreader.readline(), after cleansing string of punctuation string seems contain entire text file though instantiated line = br.readline().

here first few lines of getty.txt:

four score , 7 years ago our fathers brought forth, upon this
continent, new nation, conceived in liberty, , dedicated proposition men created equal. engaged in a

i have attached code below context.

private static objectlist getwords(string filename) throws ioexception {     bufferedreader br = new bufferedreader(new filereader(filename));     objectlist wordlist = new objectlist();     int linecnt = 1;     int positioncnt = 1;     string line = br.readline();     system.out.println(line);     while(line != null)     {         line = line.replaceall("\\p{punct}", ""); // somehow has access whole file string.         system.out.println(line);         string delims = "[\\w]+";         string[] tokens = line.split(delims);         (int = 0; < tokens.length; i++)         {             system.out.println(tokens[i]);         }         while(positioncnt-1 < tokens.length)         {             lineposition lineposition = new lineposition(linecnt, positioncnt);             word word = new word(tokens[positioncnt-1], lineposition);             wordlist.insert(word);             positioncnt++;         }         line = br.readline();         linecnt++;         positioncnt = 1;     }     br.close();     while (!wordlist.isempty())     {         system.out.println(((word)wordlist.removefirst()).gettext());     }     return wordlist; } 

your while loop, loops through entire file, printing line @ every iteration. wordlist contain words of file. if want work on first line, should remove while(line != null) loop.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -