string - Compare word to Text file Java -


we supposed create program reads word jtextfield , compare list, have count how many lines word if exist , display same line text file in same program jtextfield (it's supposed dictionary of sort) here have:

boton1.addactionlistener(new actionlistener(){ @override public void actionperformed(actionevent e) { string palabra=tx1.gettext(); boton3.setenabled(true); try{         // here open file         fileinputstream fstream = new fileinputstream("src/archivos/translator.txt");         datainputstream entrada = new datainputstream(fstream);         bufferedreader buffer = new bufferedreader(new inputstreamreader(entrada));         string strlinea;         while ((strlinea = buffer.readline()) != null)   {               system.out.println (strlinea);         int i=0;         while (!(strlinea.equals(palabra))){         i++;          }   tx2.settext(string.valueof(i));         }         entrada.close();     }catch (ioexception x){          system.err.println("oh no, ocurrió un error: " + x.getmessage());     } 

}} );

based on understanding of said, first, should change:

while (!(strlinea.equals(palabra))){ 

to

while (!(strlinea.contains(palabra))){ 

you want see if line contains word, not line same contents of textarea. also, you'll want add statement contents of while loop. it'll increment "i" forever if word doesn't come in document. want move strlinea next line if current 1 doesn't have it, , if does, you'll want terminate loop.


Comments

Popular posts from this blog

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

php - facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1 -

hadoop - Sqoop installation export and import from postgresql -