Hi Guys, I am Reading a number of text files in directory for sending as attachments. Apparently, I am only interested with the text files that contain an e-mail address on the eighth Line. If the text file does not contain a valid address or the line number 8 is null, it should be deleted. Am using this piece of code that does not seem to be working. Please Help.
Where Could I be getting it wrong?
Give a beggar a fish; feed him for a day. Teach him how to fish; Feed him for a lifetime.
Stanley Mungai wrote:All files have more than eight Lines, you can be sure about that.
Your code would be more robust if it won't crash anyway, by being able to handle file with less than 8 lines, even if it "never" happens. In that case you could just delete the file without having to check for an email address.
Stanley Mungai wrote:Apparently, I am only interested with the text files that contain an e-mail address on the eighth Line.
Apparently? Does that mean the directory could contain files that aren't text files?
The only way I know to do that is to check the 'magic number'; but I have no idea if it works on any system but Unix/Linux - and I also don't know if there's any equivalent for Java (I'd doubt it, unless it's a cross-platform solution).
It has to be said that the chances of a non-text file read as text is highly unlikely to produce a match.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here