| | |
how can we delete a directory in java???
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hi alpe gulay,
It seems from your questions that you are a bit of a beginner at Java. Take a look at the post at the top of this forum. It contains several great links that might be able to help you in your journey. The website java.sun.com is particularly helpful, with tutorials, examples and the API documentation as well as many other Java resources.
In answer to this specific question, there are probably many ways to do what you want. Off the top of my head I would suggest taking a look at the java.io.File.deleteOnExit() method for a simple way of deleting any file (and therefore directory) when the virtual machine terminates.
Hope this helps,
darkagn
It seems from your questions that you are a bit of a beginner at Java. Take a look at the post at the top of this forum. It contains several great links that might be able to help you in your journey. The website java.sun.com is particularly helpful, with tutorials, examples and the API documentation as well as many other Java resources.
In answer to this specific question, there are probably many ways to do what you want. Off the top of my head I would suggest taking a look at the java.io.File.deleteOnExit() method for a simple way of deleting any file (and therefore directory) when the virtual machine terminates.
Hope this helps,
darkagn
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. A directory is deleted just like any file - with File.delete(). A directory must be empty to be deleted, so if it contains files you must recurse the directory and delete all files and subdirectories first.
•
•
Join Date: May 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
.,'is any knows the code to delete a directory in java...
help me pls...
YOUR ANSWER IS HIGHLY APPRECIATED!..
Like this
// Deletes all files and subdirectories under dir.
// Returns true if all deletions were successful.
// If a deletion fails, the method stops attempting to delete and returns false.
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
![]() |
Similar Threads
- Force Delete? (Java)
- hijackthis log... what to delete?? (Viruses, Spyware and other Nasties)
- Compile Java (Java)
- Ftp (Java)
- How do I delete FakeMSNBeta? (Viruses, Spyware and other Nasties)
- Java Compiler not working (Java)
- Blue screen, and Trojans that I can't delete (Viruses, Spyware and other Nasties)
- I Cannot Delete, Move, or Rename a File On My PC. (Viruses, Spyware and other Nasties)
- Hijackthis log: what do I delete? (Viruses, Spyware and other Nasties)
- my hijackthis log is longer, what can i delete (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Netbeans and query
- Next Thread: How can I delete empty lines from file?
Views: 4465 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool keyword linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time tree web windows






