How to detect EOF in Java?

前端 未结 3 1316
予麋鹿
予麋鹿 2021-01-04 13:57

I\'ve tried some ways to detect EOF in my code, but it still not working. I\'ve tried using BufferedReader, Scanner, and using char u001a to flag the EOF, but still not make

3条回答
  •  爱一瞬间的悲伤
    2021-01-04 14:21

    This is what I did

    Scanner s = new Scanner(f); //f is the file object
    
    while(s.hasNext())
    {
    String ss = s.nextLine();
    System.out.println(ss);
    }
    

    Worked for me

提交回复
热议问题