List directory with 40000 files.

C

Calvin Tai

Dear all,

I have a directory with more than 40000 files inside. I want to write
a java program to do something on each of the file by the following
code.

File sdir = new File(srcDir);
String[] filename = sdir.list();

// For each file, do something
for(int i = 0; i < filename.length; i++)
{
// Do something
}

Since the maximum of integer cannot exceed 40000, the above code will
generate error for sure. Then how can i accomplish the task with files
more than 40000 in a directory? Thanks.

Best regards,
Calvin
 
J

Jacob

Calvin Tai wrote:

I have a directory with more than 40000 files inside. I want to write
a java program to do something on each of the file by the following
code.

File sdir = new File(srcDir);
String[] filename = sdir.list();

// For each file, do something
for(int i = 0; i < filename.length; i++)
{
// Do something
}

Since the maximum of integer cannot exceed 40000, the above code will
generate error for sure. Then how can i accomplish the task with files
more than 40000 in a directory? Thanks.

The limit of int is 2147483647.
 
T

Thomas Weidenfeller

Calvin said:
Since the maximum of integer cannot exceed 40000,

Try to dig up some Java language reference. You will find that int can
hold much larger numbers. int is 32 bits in Java.

/Thomas
 
S

Stefan Poehn

Thomas Weidenfeller said:
Try to dig up some Java language reference. You will find that int can
hold much larger numbers. int is 32 bits in Java.

One of these bits is the sign bit.

Why doesnt Java have unsigned int, and long?
 
R

Roedy Green

Why doesnt Java have unsigned int, and long?

You don't really need unsigned int since you can use long it its
place.

Lack of unsigned byte is what annoys me most. Don't thing I have ever
wanted a signed byte.

Unsigned longs would also require unsigned * and / > < etc. operators
in the JVM. Trying to keep the byte code operands down to one byte
make the byte code compact and fast for small machines that interpret.


There would not be any need for new operators other than load unsigned
byte to handle unsigned byte. You could even do at it the compiler
level by adding & 0xff after every byte load.
 
L

Liz

Calvin Tai said:
Dear all,

I have a directory with more than 40000 files inside. I want to write
a java program to do something on each of the file by the following
code.

File sdir = new File(srcDir);
String[] filename = sdir.list();

// For each file, do something
for(int i = 0; i < filename.length; i++)
{
// Do something
}

Since the maximum of integer cannot exceed 40000, the above code will
generate error for sure. Then how can i accomplish the task with files
more than 40000 in a directory? Thanks.

Best regards,
Calvin

Sounds like a stalling tactic. How come you didn't just try it (should
take under 10 minutes to do.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top