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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>>in JBoss app server's Bin directory .

Isn't that rather dangerous?
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 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.
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
> You can also create a temp-file in Java using File.createTempFile () if I remember the name correct.,%20java.lang.String,
Mayank SAssociate Director - Product EngineeringCommented:
The accepted answer is almost same as File.createTempFile () ;-)
Thanks, calju.

Indeed, many ways lead to the target.

mayankeagle, don't sob: it's only C
Mayank SAssociate Director - Product EngineeringCommented:
Ha ha :) that's not the problem, buddy. Just kidding.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.