I have a file with some lines and I have to validate each line by retrieving a number in these lines.
I'm using the Scanner class to retrieve my lines, but when I need to retrieve the number (in position 80 by example), i don't have an other idea than to use the substring method, someone has a better idea? That's not very beautiful ;)
You can also look into tokenizing your string, which may or may not work. That would assume the data is always in the Xth token.
Or you may have to look for some other marker, like "score: ", and then get the characters after that up to some other character, like a semi-colon...
This is where programming becomes more of an art than a science...you need to analyze your data and figure out where the piece you want will be, and then determine how to get it. So I'd say first start by analyzing your data, and come up with an algorithm for finding the data you need in the line.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Fabian Angy wrote: . . . An other question about Scanner, there's a way to know the previous line, the current line and the next line?
The only way to know the next line is clairvoyance
You are going to have to store them. You could write yourself a List class which has a fixed size and automatically deletes the oldest member. Or a Queue might do the same. There might be something already available: try Apache Commons if you can't find anything in the Sun/Oracle API. Or try a 3-member String array.