Forums Register Login

Problems deleting files

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
Another thing to consider. If a process has a lock on the file your Java process may be unable to delete it.
+Pie Number of slices to send: Send
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.
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 735 times.
Similar Threads
URLyBird read() method
Question on ftp.
Stream for reading and deleting line
saving uploaded file to temp folder in a multi-threaded web application
Deleting data form a file?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:50:09.