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 / December 2005

Tip: Looking for answers? Try searching our database.

Ensuring directory deletion has complete

Thread view: 
Mark - 07 Dec 2005 10:50 GMT
I am writing a program that adds and removes files cleaning up empty
directories when the last file has been removed; it also automatically
creates the directory when a new file needs to be written.  During
testing I have discovered that if a directory is removed and then
recreated in quick succession the directory creation sometimes fails.
The following code highlights this error.

import java.io.File;
public class TestMkdirs {
   public static void main(String[] args) {
       File test = new File("test");
       for (int i=0; i<100; i++) {
           test.delete();
           if (!test.mkdir()) {
               if (!test.exists()) {
                   System.err.println("Could not create " + i);
               }
           }
       }
   }
}

The output is:

Could not create 2
Could not create 3
Could not create 4
Could not create 5
Could not create 6
Could not create 7
Could not create 8
Could not create 9
Could not create 10
Could not create 11
Could not create 12
Could not create 13
Could not create 14
Could not create 15
Could not create 16
Could not create 17
Could not create 18
Could not create 19
Could not create 20
Could not create 21
Could not create 22
Could not create 23
Could not create 24
Could not create 25
Could not create 26

So it fails about 25% of the time.  I am using suns jvm 1.4.2_10 on
windows xp sp2,  I have also disabled the virus guard to check if that
is causing a problem but still get the same issue.  I have also put
print statements on the delete method checking that it only failes to
delete when the directory does not exist and this is always the case.

What I really need is something like FileDescriptor.sync() for
directory deletion to ensure it has really happened at the o/s level
before continuing.

Any help would be gratefully appreciated
Rodrigo Zechin - 08 Dec 2005 14:05 GMT
Wel... if JNI is an option it would be really simple to do so.
I don't know anything better than FileDescriptor.sync(), so if it's not
working I would go in a lower level with native code.

Zechin


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



©2008 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.