We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Deleting the File forcefully using JAVA

calju
calju asked
on
Medium Priority
12,529 Views
Last Modified: 2010-07-27

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.

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
>>in JBoss app server's Bin directory .

Isn't that rather dangerous?

Commented:
whts the error message u are getting ?

first of all, can u delete the directory when the server has started ? (just hav a check)
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
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.

Commented:
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.
CERTIFIED EXPERT
Top Expert 2004

Commented:
Q1)  Which version of JBoss?
Q2)  How are you trying to delete the file?  (source code?)
Q3)  Which version of Java?
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!
     

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> 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)
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
The accepted answer is almost same as File.createTempFile () ;-)
Thanks, calju.

Indeed, many ways lead to the target.

;JOOP!
mayankeagle, don't sob: it's only C
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Ha ha :) that's not the problem, buddy. Just kidding.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.