EvilZone
Programming and Scripting => Java => : DreX March 07, 2015, 03:59:12 PM
-
http://pastebin.com/rDD90Nnb# (http://pastebin.com/rDD90Nnb#)
I don't know why some files can be read and some can't.
The main difference I can see, is that small files (2 lines) can be read while larger files can't be.
Is there some sort of limitation on this?
-
I'm awful in java but why are you using fileHandler.hasNext() but then you're trying to get line. Has next it's about token, not about line. Try to use hasNextLine() (http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#hasNextLine%28%29)
And it would be great if you could describe what errors you have
-
I'm awful in java but why are you using fileHandler.hasNext() but then you're trying to get line. Has next it's about token, not about line. Try to use hasNextLine() (http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#hasNextLine%28%29)
And it would be great if you could describe what errors you have
changing it doesn't fix the problem and the program doesn't crash or anything. It just doesn't bring up the txt file.
Here is an example.
When I open "mapmaking.txt" it displays both links but when I open "test.txt" it doesn't show anything (as if i did nothing).
-
So, why you just not debug the program?
add break point to the hasNext loop and go trough lines step by step.
-
It is an issue with the characterset that the scanner applies implicitly. Has nothing to do with the size of your files, but whether they happen to have the correct charset. If any character of your file is outside of the applied charset's range, the scanner's hasNextLine will return false.
Specify the correct characterset and you are fine, e.g. with
Scanner fileHandler = new Scanner(newFile, "latin1")
your test.txt will work fine.
So, why you just not debug the program?
add break point to the hasNext loop and go trough lines step by step.
This won't help here, because the logic in the code is fine.
Also, that's a pretty lazy answer, you can tell everyone who has issues with a program.
-
This won't help here, because the logic in the code is fine.
Also, that's a pretty lazy answer, you can tell everyone who has issues with a program.
Yeah, as I said I don't know java a lot. This is thing which I could say. Maybe it could be helpful.
And I still think that debug is helpful because OP could find that hasLine() returns false in case if file is still not ended. And then, knowing that hasLine() returns false, OP could write it here and we would try to understand why hasLine() couldreturn false.
But yeah, I will try to be more helpful in future...
-
And I still think that debug is helpful because OP could find that hasLine() returns false in case if file is still not ended. And then, knowing that hasLine() returns false, OP could write it here and we would try to understand why hasLine() couldreturn false.
Indeed, that could help.
-
It is an issue with the characterset that the scanner applies implicitly. Has nothing to do with the size of your files, but whether they happen to have the correct charset. If any character of your file is outside of the applied charset's range, the scanner's hasNextLine will return false.
Specify the correct characterset and you are fine, e.g. with
Scanner fileHandler = new Scanner(newFile, "latin1")
your test.txt will work fine.
Yp, it works.
Thank you very much.