| | |
how can we delete a directory in java???
![]() |
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?
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class client code color component count database derby design eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui homework html ide if_statement image integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia keyword linux list macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object open-source os problem producer program programming project projectideas property read recursion reference replaysolutions ria scanner search server set size sms sort sourcelabs splash sql sqlite stop string swing threads transforms tree ui unicode validation windows






