Re: Jumps over while-loop
What would cause the while loop to be skipped?
Since the while loop appears in main, we can assume for now that main is being called...
What is the value of fil.hasNext() the first time the while loop is encountered?
Try a print line before the while loop to see the value of fil and fil.hasNext() and see what is going on
Re: Jumps over while-loop
Ok, I tested "fil.hasNext" before the While-loop, and the value was "false". The value of "fil" was:
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\*][decimal separator=\,][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q�\E][infinity string=\Q∞\E]
I really can't figure out what is wrong. The file does exist and it is not empty.
--- Update ---
Ok, I tested "fil.hasNext" before the While-loop, and the value was "false". The value of "fil" was:
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\*][decimal separator=\,][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q�\E][infinity string=\Q∞\E]
I really can't figure out what is wrong. The file does exist and it is not empty.
Re: Jumps over while-loop
A common cause of this problem is there is more than one version of the file present in different folders and the program is trying to read the wrong one.
How are you executing the program?
Re: Jumps over while-loop
Okey, thanks! I'm executing the program through Netbeans - run file. I found a solution:
I just replace Scanner fil = new Scanner(new File("ord.txt")) with Scanner fil = new Scanner(new FileReader("ord.txt")).
Why does that work and not just with "File"? I don't have a clue.
Another question: Do you recommend having "String testOrd = fil.nextLine()" inside the while-loop or is it another solution? A new object is created for each lap and the old ones will act as garbage in the memory. I've read that Java can sort this out by itself, but it may slow the execution down a bit.
Re: Jumps over while-loop
Look at the contents of the ord.txt file in a hex editor and see what the first few characters of the file is.
What OS are you on?