java - Text printing in an infinite loop -
this question has answer here:
- reading , displaying data .txt file 10 answers
the text printing in infinite loop. way avoid these?
if (eload) { file file = new file("reservation.txt"); /** reading file */ try(fileinputstream fis = new fileinputstream(file)) { int content; while ((content = fis.read()) != -1) { // convert char , display system.out.print((char) content); /**print out result contents of file. */ } } catch(ioexception e) { e.printstacktrace(); } }
ooutput shown
homeworkdue sat oct 10 00:00:00 pdt 2015 23:00 23
homeworkdue sat oct 10 00:00:00 pdt 2015 23:00 23
homeworkdue sat oct 10 00:00:00 pdt 2015 23:00 23
can add
system.out.print(content);
after
system.out.print((char) content);
i'm not knowledgeable yet in programming may because reading fis.read() ascii values, , either 000 or 003.
if put
content = fis.read()); while (content != 3 && content != 0 || content == null) // if either not 3 , not 0 doesn't run or if isn't defined { // stuff }
for while condition
quote: "that means, api try read line of file, -1 , returns eof." (looks doesn't return -1)
looked at: https://superuser.com/questions/789026/eof-ascii-hex-code-in-text-files
Comments
Post a Comment