Basic idea; crawl my mp3 collection in a quick and dirty way and print the filenames of my mp3s in a text file.
So far so good, I have the same structure of artists and albums for almost all of my mp3s. It goes:
Amon Amarth -> Deceiver of the Gods -> mp3s
I know there are some cases that the structure goes:
Artist -> Album Name -> CD1 -> mp3s
but this shouldn't be a major problem.
When I run the program, it does create a file and save contents but at some point the program crashes with a NullPointerException leaving the file incomplete. If I remove the album that the program crashes into, it will crash at some other point. If I test the program in a much smaller root directory, it will finish no problem. My mp3 collection directory is 60GB of mp3 counting at ~8000mp3 files.
The line is the 25 in my above code. Clearly at some point the albumContent is null.
What baffles me is this though; in my Metal directory it will NPE. In a Metal2 directory (much smaller than Metal) it will traverse the dirs correctly and won't NPE. That's what I don't get. It works in one root directory and not in another.
All right so: I decided to change my implementation and use the nio API in case it threw better exceptions than using File arrays. It did!
It turns out, it was the bloody desktop.ini files that caused the problem. I don't know why or how but I guess they didn't count as "files" maybe? After I removed the "problematic" albums, it traversed my collection just fine.
There you go... you assumed that something in your file system was either a file or a directory, but then you got stabbed in the back by Windows. By the way there's a File.isFile() method which might work more reliably for determining if something is a file, but I haven't tested it on your test case so I could be wrong.
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.