Read a text file until EOL in Java

前端 未结 3 1155
萌比男神i
萌比男神i 2021-01-29 08:07

I am trying to read a text file which has -

hello James!
How are you today!

I want to read the each character in the string till i find EOL ch

3条回答
  •  被撕碎了的回忆
    2021-01-29 09:00

    Your problem is about magic numbers.

    your while will enter into an infinite loop in the case charAt(21)!='\n' && charAt(22)!='\r'

    those two integers shall be increased inside the loop.

    charAt(i)!='\n' && charAt(i+1)!='\r'
    ::inside loop
      i++
    

提交回复
热议问题