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