File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Design question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Design question..." Watch "Design question..." New topic

Design question...

Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
I'm trying to make a list, set, map, (alright, I really don't care what it's called, as long as it works! ) of all of the directories and files on my hard drives.

I've started writing code. Found some on a website, and have tried to implement it. Here's the problem. Array, Vector, and HashSet all to up to int size, or 32,000 + entries. My problem is that I currently have over 100,000 files on one drive alone.

To be fair, I've only compiled it. Haven't run it yet. I'm not sure how many bugs in it! However, at this point, I'm more concerned with how to get a real list of the complete file names including drive, sub-directory, and file names.

Here's my code:

package BackupClient;

import java.util.Vector;

class DirectoryTree {

private Vector files; // here's the main table
private Vector directories;

protected long totalEntries() {
return (long) files.size();

protected String getFirstDirectory() {
return (String) directories.firstElement();

protected String getDirectory(int i) {

return (String) directories.get( i );

protected String getFirstFile() {
return (String) files.firstElement();

protected String getFile( int i ) {
return (String) files.get(i);

/** Creates a new instance of Directory */
protected void DirectoryTree() {
files = new Vector();
directories = new Vector();

File dir = new File("c:\\");

// Put all File names into lhs...
private void visitAllDirsAndFiles(File dir) {

// first we add the file name
if ( dir.isFile()) {

if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
visitAllDirsAndFiles(new File(dir, children[i]));
} // for
} else {

}// if
} // visitAllDirsAndFiles

} // Directory

Do I really have to go to an RDBMS and make a table at this point already?

Any thoughts would be appreciated.

Marcus Laubli

Marcus L´┐Żubli, SCJP 1.4, CLP 5.0, SCWCD 1.4 (preparing)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

None of these classes have any practical size limits. There are theoretical limits near 2 billion entries, but since no existing JVM can support a large enough heap to exceed this, it's not of practical concern (and disk drives that can contain more than 2 billion entries are still rather rare as well, and no flavor of Windows would support one that did.)

Where did you get that 32,000 number? That's the maximum positive value of a signed 16-bit int, but Java ints are 32 bits.

Don't use Vector in new code; it's a legacy class that's been superceded by ArrayList.

Finally: so tell us why you want to do this, anyway? What is the list for? Why make a list rather than simply visiting each file in order without storing the paths?

[Jess in Action][AskingGoodQuestions]
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
Oops, I mis-thought. I did know that a short is 16 and an int is 32 bits. I guess I needed a kick in the britches!

A couple of days ago I posted a query in this forum, asking whether anyone was interested in helping even define the requirements, but got no takers. Here's what I'm trying to do:

I'd like to create a simple client / server app that takes each file from the client machine, runs it through a "ZipOutputStream", serializes and sends it out to a second machine via IP to make a compressed backup of each individual file (in the correct directory tree) at least once a day, however, possibly multiple times a day.

I know that this is very simplified, however, I have someone who would actually like to try to do his backups off-site, and I thought I could "cut my teet" on a project of this size.

We may or may not have to make a GUI to deal with backup and restore options, features, etc. This can be discussed in a group forum.

I'd be delighted to do a full open-source project and leave it here on for others.

As for the question of why I wanted to make an array, I was just trying to see what kind of challenges I'm going to run into when I do start building.

Any takers for this kind of project? I think it would be kind of fun! If so, where on the ranch would be the right place to start this kind of project? Is there a barn, or do we have to go out to the forest!?

Looking forward to your reply!

Marcus Laubli
I agree. Here's the link:
subject: Design question...
It's not a secret anymore!