Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

How can I check how many files with specific names exist in a directory?

Thread view: 
John - 16 Apr 2007 18:40 GMT
I am writing a generic database with many independent data files named
data1.dat, data2.dat,...

For a user to resume entering new data file, the application must check how
many already exist when it start.

Is there anything like file.exist() to can perform such action?

Do I have to write loop to track all files or maybe there is some similar
function already embedded in Java?

John
Joshua Cranmer - 16 Apr 2007 19:17 GMT
> I am writing a generic database with many independent data files named
> data1.dat, data2.dat,...
[quoted text clipped - 8 lines]
>
> John

What you want to look at the list() or listFiles() functions of the
java.io.File class. You may also want to investigate the FileFilter or
FilenameFilter class as well.

AFAIK, there is no function in Java that will automatically manage a
data_n.dat system of files unless they are being used for logging.
Real Gagnon - 16 Apr 2007 23:01 GMT
> For a user to resume entering new data file, the application must
> check how many already exist when it start.

First you create a class that implements java.io.FilenameFilter and then
code the accept() method, then call File.list() with the filter as a
parameter.

Example at
http://www.rgagnon.com/javadetails/java-0055.html

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.