Java equivalent for MFC findnextfile

J

jaja

Hello,
How can I iterate the files inside a directory, like FindNextFile in
Win32.
I don't want to use File.list() which returns me a list of all files.
Thanks.
 
A

Andrew Thompson

jaja wrote:
...
How can I iterate the files inside a directory, like FindNextFile in
Win32.

File.list() or File.listFiles() should provide a list you can iterate..
I don't want to use File.list() which returns me a list of all files.

You poor thing. Have you considered hiring someone to
code this for you? I am guessing it will save you a lot of
stress.
 
T

Thomas Fritsch

jaja said:
How can I iterate the files inside a directory, like FindNextFile in
Win32.
I don't want to use File.list() which returns me a list of all files.
Why not?
 
J

jaja


Because in case of a huge number of files, the list is very large and
memory consuming.
Do you know a way that I can iterate the files and get it one by one?
Thanks.
 
A

Andrew Thompson

jaja said:
Because in case of a huge number of files, the list is very large and
memory consuming.

Over optimisation.
Do you know a way that I can iterate the files and get it one by one?

Implement a NextFileFilter that extends FileFilter and
feed it to File.listFiles(nextFileFilter). But I expect the
JVM will ultimately fetch the entire file list before being
able to determine which is the 'next' file.
 
C

Christian

jaja said:
Because in case of a huge number of files, the list is very large and
memory consuming.
Do you know a way that I can iterate the files and get it one by one?
Thanks.
Are you really shure you need this kind of optimization?

usual directorys should have less than 10k files in them which should
mean less than 500 kiB of Memory, any problem with that?

if you have more than a 100k files per dir and need to have multiple
lists of such large directorys .. well.. first I would recommend you to
check the program that produced these horrible mess of files as this
could crash your filesystem .. or at least give it a hard time.

Christian
 
R

Roedy Green

How can I iterate the files inside a directory, like FindNextFile in
Win32.
I don't want to use File.list() which returns me a list of all files.

..list is the Java idiom. It is probably considerably more efficient
to wind up the JNI .list method only once to get them all.
 
R

Roedy Green

.list is the Java idiom. It is probably considerably more efficient
to wind up the JNI .list method only once to get them all.

There is a considerable overhead crossing the blood-brain barrier into
the JNI world. .list has to cross it only once. findNextFile would
have to cross it N times.
 

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

Similar Threads

Java 0
File.list 1
Java MemoryLayout/ValueLayout Questions. 2
search for files 22
Java with Netbeans 2
Java <-> MFC? 12
Regarding for Stand Alone Java Compiler? 2
Information with WMI in Python. 1

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top