Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10920
  • Last Modified:

Deleting the File forcefully using JAVA


I created a directory(actual) in JBoss app server's Bin directory .
I am storing image files in that directory.
I can able to read and write in to the files.
But i could not able to delete that files.
I closed all the input and outputstreams ,i used.


After i performing R/W operation i want to delete that files (Forcefully).

I need a soution for this.

0
calju
Asked:
calju
1 Solution
 
CEHJCommented:
>>in JBoss app server's Bin directory .

Isn't that rather dangerous?
0
 
avinthmCommented:
whts the error message u are getting ?

first of all, can u delete the directory when the server has started ? (just hav a check)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I don't think you will be allowed to delete any file within the same directory in which the server has been installed without stopping the server. If you create the directory programatically for storing files temporarily then why cannot you create it on another location, outside of the server's directory? You can also create a temp-file in Java using File.createTempFile () if I remember the name correct.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
omry_yCommented:
maybe the jboss process lock the directory.
try a different directory for this, maybe use the temporary file API (File.createTempFile).

there is not API in java to force deletion of a file.
in fact, its an OS issue - I assume you use Windows- and in Windows, applications can lock files, and these files can't be deleted.
that is the main reason for all the windows reboots needed when installing some programs, btw.
on Linux/Unix you will not have a problem to delete the files.
0
 
TimYatesCommented:
Q1)  Which version of JBoss?
Q2)  How are you trying to delete the file?  (source code?)
Q3)  Which version of Java?
0
 
sciuriwareCommented:
1) put the file in a temp directory, like C:\TMP or /tmp (on linux/unix),
2) after creating the File object, practise:
       File f = new File(.....................................);
         f.deleteOnExit();    // And no worries anymore.

;JOOP!
     
0
 
objectsCommented:
> You can also create a temp-file in Java using File.createTempFile () if I remember the name correct.

http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
The accepted answer is almost same as File.createTempFile () ;-)
0
 
sciuriwareCommented:
Thanks, calju.

Indeed, many ways lead to the target.

;JOOP!
0
 
sciuriwareCommented:
mayankeagle, don't sob: it's only C
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Ha ha :) that's not the problem, buddy. Just kidding.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now