java - Scanning a text file -
it simple question. have problem scanning text file. want scan text file , show message in joptionpane. scans shows first line of text file , stops disregarding other lines. if can little help. thank much! here code:
file file = new file("src//mytxt.txt"); try{ scanner input = new scanner(file); while(input.hasnext()){ string line = input.nextline(); joptionpane.showmessagedialog(null, line); return; } input.close(); } catch (filenotfoundexception ex) { joptionpane.showmessagedialog(null, "file not found"); } }
using while (input.hasnext()) { // scan , append each line string variable
}`
scan each line file , keep whole text in string variable. use joptionpane.showmessagedialog(null,op) show whole text in single joptionpane.
Comments
Post a Comment