how to check the end of a file in java
<p>I have the following code:</p>

<pre><code>String log = "/ws/priyapan-rcd/label" + "priyanka_label_test" + ".log";
File file = new File(log);
String line = null;
try {

        Scanner scanner = new Scanner(file);
        while (scanner.hasNextLine()) {
               line = scanner.nextLine();
                System.out.println("come inside loop to check end of file");
                if (line.contains("script ran successfully")) {
                    System.out.println("line found.go out of loop now");
                    break;
                }
                else{
                    System.out.println("come inside loop to check logs.label update faild");
                }
}
}catch(Exception e){
    System.out.println("exception occured");
}
}
</code></pre>

<p>Everytime I execute this only the <code>else</code> part is executed. The <code>if</code> part never gets executed.</p>

<p>Can somebody help me figuring out what is wrong in my code?</p>