• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems deleting files  RSS feed

 
Carlos Vassallo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to simply delete a file from local machine. I just read a lot of forum questions and answers without make it work.
The os is a NTFS, the permissions of the file are full control for everyone (and for SYSTEM).
SecurityManager.checkDelete("path_to_the_file") throws always a SecurityException and that means that the method delete() from the class File never will do that.
I only can read the file...
somebody have any suggestions ?
Thanks !
sorry, my english is a little bad
 
Alain Boucher
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the File.delete() doesn't work and you have the OS permission to do that, maybe you have a Java 2 Security issue... check the java.security file to see if you can delete file, if the permission in grant to you. Usualy, if you use the Sun SDK 1.4, you have all access to the file system, but if you use another JVM like a application Server one, maybe the right are not grant.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Alain's advice. Unfortunately I don't know more about security manager configuration offhad, so nothing to add there. However, if you are unable to fix the problem by configuring the security manager, you may wish to bypass File's delete() method and instead delete the file using Runtime's exec() method to issue a command directly to the OS. This isn't portable to other OS's, and is a bit complex to set up correctly - but at least it's another option, if you need it.
 
Carlos Vassallo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks for yours responses, by the way, I choose the second chance (it`s a simple bat like "del %1" ).
What I see is that something haves the lock of the file, althought I only create a File object. I didn't try to read with a BufferedReader (in that case, if I don't close de BufferedReader, the file is opened by that object and I couldn't delete him).
Again, thanks for your time and yours lines.
Saludos:
Carlos.- (MCP VB, JCP 1.4)
 
Van Glass
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing to consider. If a process has a lock on the file your Java process may be unable to delete it.
 
Carlos Vassallo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The own of the process is a trigger monitor of IBM MQ Series, my code works fine on other circunstances I mean that if I run this code on a local machine directly from a cmd, the files are deleted. I'm using java 1.3.
Thanks again for your hand.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!