• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with delete a file

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
I have a problem with delete a file.

Sample code:

File f=new File(source);
for(int i=0;i<=file.length;i++)
file[i].delete();

This code is run perfectly when i testing a simple program.
but in my project this code is not able to delete the files,it
always returns false. I closed all streams which i used but it not deleting a files.Please Help Me..

Thanks in advance
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by abiram kumar:


Sample code:

File f=new File(source);
for(int i=0;i<=file.length;i++)
file[i].delete();



What is the environment for you project? Here is what I faced a few months back , might be useful to you.

My code to delete was running fine in the development environment (Windows 2000) , but was failing in production environment (UNIX).

The reason is the source.When I trimmed this it worked file in UNIX also.FileSystem implementation are different for different filesystems and file are closely related to those.I think in case of a UNIX file , it takes the source as source and if the source string has some spaces in the end , then the File object that you have created might not be a valid descriptor to a file in the filesystem.
In case of NT filesystem implementation they might be taking care of that.
 
chennai Kumar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply rahul,My project development is runing in windows xp.Even i trim source string,not deleting the file.Still boolean value is returns false.
Please help me...
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then some other live descriptor might be there for that file or the user id with which JVM is running might not have enough permission to delete the file.
 
chennai Kumar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I gave all permission to directory,but i run simple program(Separate program)it deleting all files properly.but i Implement in project delete can not work properly.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Rahul. This problem is usually caused by an open stream. I'd put more debugging in your code. Print out the file location so you know you are trying to delete the file you think you are deleting. Check File.exists() and the return value of File.delete to narrow down what's going wrong.
reply
    Bookmark Topic Watch Topic
  • New Topic