java - Text printing in an infinite loop -


this question has answer here:

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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -