Simple and fast recursive find files for Java

This week I needed a simple routine to find files inside a given folder and respective sub folders.

There are plenty of solutions around the web, but these solutions typically use a second method or even more, instead of a single recursive method.

Below is the code that I've written, it is not perfect nor fully tested but it is simple and fast on my Toshiba R630 Win7 laptop (indexed 152450 files in 30Gb of data under 12 seconds), so I'm happy and decided to share this code snippet with the rest of the world.

It will output an array list composed of File objects. You only need to define where (the starting folder) and maxDeep (the level of subfolders that you want to crawl).

If you have suggestions for future improvement, please do mention them and I'll update the snippet along with placing your name on the credits. I liked this solution but I'm by no means a coding guru.

Have fun!

You find the snippet at this doc:

--- update 1 (23th March 2011), the code was made shorter and simpler. Please update.

--- Benchmarks
Testing on drive D: with 30Gb of data took an average 12 seconds for 152 450 files
Testing on drive C: with 92Gb of data and 476 789 files started with 829 seconds on the initial scan and on posterior scans dropped to an average of 140 seconds.

Machine of these testings was a Toshiba R630, equipped with 4Gb of RAM, an i7 core and Windows 7 x64 bits.


How to change the default icon on a Java Frame

When you create a Java frame, it usually comes with the default Java icon on the window title.

It is not a bad icon, but you might want to customize that portion after a while.

All you need to do is place this code snippet on the initialization part of your frame:


I've simply placed a .png image on a folder called "media" on the root of my project.

Have fun.

A day in my life

Well, are you curious about knowing how a day on my life is?

The answer is quite simple:

function starNormalDay()
// initiate procedure to move outside of bed
While normalDay()
sleep(7 hours);


* We wake up at each day, this is life

function wakeUp()
if isMorning()
if weekDay is (saturday or sunday)
while ( < 10h00)
sleep(10 minutes)

You see? Sometimes life is easy to explain. What do you think?


The end of March

The end of this month marks several deadlines that need to be meet.

A new project will be presented, this follows a lot of new troubles and issues that need to be dealt until the deadline expires.

We are still running short on resources. Things are certainly not going as planned and development seems to progress far slower than desired.

Nevertheless these nuisances, the progress made during the past two months is certainly something that leaves me proud to think about. We've managed to create a slim framework that combines essential components for any application to survive the upcoming decades.

We've created a Message Queue to pass messages between applications, a Process Manager to store informations about each applications, a dynamic database storage that can adopt any other technology in the future and a network component that extends the local message queue to interact with remote message queues in other instances in a fully transparent and asynchronous manner.

All of this is certainly not something to undergo with light head. A lot of effort, commitment, rewriting and brainstorming was needed until we were proud of the result.

And the result is nice. We've built a functional enterprise framework that is probably one of the smallest in the world. Using no more than a total of 2Mb and little above 10Mb of RAM while running at full speed.

Unfortunately, the deadline is indeed tight. It takes time to write test cases, to write documentation, to fine tune our code to work as intended, but things still move on.

We've been thinking about the licensing for this new framework and that is one of my biggest headaches. I want this new tool to be free and follow the traditions of all my previous works. I would also like to try out the open source way of doing things.

But several issues concern my imagination:

- If an idea is innovative, how can one prevent large corporations from creating their own "better" versions. I say this because we don't have the muscle or desire to compete against big players but they'd have a galore of fun just looking at the code and throwing all our effort into oblivion

- Open source allows branches and more often than not some wild-coder will just pick the code, create a new branch and then advertise it as better instead of contributing to a longer standing project, effectively fragmenting and eroding any community built around the tool or killing any will of the original developers to fell motivated and follow progress

These are some of the issues that our time constraints urge to solve. Personally, I prefer to look on the bright side of things and adopt an "I don't care" approach. If these are the problems that we cannot find a proper answer, then I guess that it will be better to follow with the same licensing model used with success for Winbuilder.

Completely free but closed source. On the other hand, I would really like to try out the open source for a change. I am just not ready to open my hand after so much hard work over the past 14 months to see it "used" as a commercial product by someone of ill intentions.

Time to think more about the licensing mode.