java - BufferedReader Looping Incorrectly -


i know simple, cannot seem find have done wrong.

i comparing output webpage contents of text file. have following code , appears every result webpage bufferedreader loops through 1 time. less confusing once post code , results.

code

string docone = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div/div/h5")).getattribute("textcontent").tostring(); string doctwo = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[2]/div/h5")).getattribute("textcontent").tostring(); string docthree = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[3]/div/h5")).getattribute("textcontent").tostring(); string docfour = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[4]/div/h5")).getattribute("textcontent").tostring(); string docfive = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[5]/div/h5")).getattribute("textcontent").tostring(); string docsix = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[6]/div/h5")).getattribute("textcontent").tostring(); string docseven = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[7]/div/h5")).getattribute("textcontent").tostring(); string doceight = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div[8]/div/h5")).getattribute("textcontent").tostring(); string docnine = driver.findelement(by.xpath("/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div[2]/div/div[2]/div/div/div/h5")).getattribute("textcontent").tostring();  try (bufferedreader br = new bufferedreader(new filereader("/users/vhaislsalisc/documents/cdwproductiondomainsrequireddocs.txt"))) {     string scurrentline;       while ((scurrentline = br.readline()) != null) {          system.out.println("webpage: " + docone + " required doc: " + scurrentline);         system.out.println("webpage: " + doctwo + " required doc: " + scurrentline);         system.out.println("webpage: " + docthree + " required doc: " + scurrentline);         system.out.println("webpage: " + docfour + " required doc: " + scurrentline);         system.out.println("webpage: " + docfive + " required doc: " + scurrentline);         system.out.println("webpage: " + docsix + " required doc: " + scurrentline);         system.out.println("webpage: " + docseven + " required doc: " + scurrentline);         system.out.println("webpage: " + doceight + " required doc: " + scurrentline);         system.out.println("webpage: " + docnine + " required doc: " + scurrentline);     }     br.close(); } catch (ioexception e) {     system.err.println("error: " + e.getmessage()); } 

results

webpage: research request memo (file document) required doc: research request memo (file document) webpage: research study institutional review board (irb) approval letter (file document) required doc: research request memo (file document) webpage: sample informed consent , hipaa authorization (file document) required doc: research request memo (file document) webpage: research , development (rd) committee approval letter (file document) required doc: research request memo (file document) webpage: data use agreement (file document) required doc: research request memo (file document) webpage: irb approval of waiver of hipaa-compliant authorization (file document) required doc: research request memo (file document) webpage: research protocol (file document) required doc: research request memo (file document) webpage: cdw-domain checklist (file document) required doc: research request memo (file document) webpage: va form 9957 (file document) required doc: research request memo (file document) webpage: research request memo (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: research study institutional review board (irb) approval letter (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: sample informed consent , hipaa authorization (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: research , development (rd) committee approval letter (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: data use agreement (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: irb approval of waiver of hipaa-compliant authorization (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: research protocol (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: cdw-domain checklist (file document) required doc: research study institutional review board (irb) approval letter (file document) webpage: va form 9957 (file document) required doc: research study institutional review board (irb) approval letter (file document) 

and on through rest of file

so wondering noob thing did, , how can fix goes through file 1 time , matches coming web page?

it goes through every webpage docone docnine each line in text file. i.e. compares 9 files line 1, line 2, etc.

since have pasted first 2 lines read text file, , match first 2 webpages, assume want read each line once , compare 1 webpage only. need lose while loop , call readline after displaying each result:

    scurrentline = br.readline();     system.out.println("webpage: " + docone + " required doc: " + scurrentline);     scurrentline = br.readline();     system.out.println("webpage: " + doctwo + " required doc: " + scurrentline); 

however make code harder read is. should consider using collection (or array) instead.

[edit] per gparyani's suggestion, not need call br.close() explicitly. details here http://docs.oracle.com/javase/tutorial/essential/exceptions/tryresourceclose.html


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -