Solved

Delete nested folder in JSP?

Posted on 2002-07-01
6
346 Views
Last Modified: 2010-07-27
How to delete a nested folder that contains files/sub folders in JSP?

thanks.
0
Comment
Question by:trowa
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:mraible
ID: 7121845
Same way you would in java.

Look at java.io.File in the Javadocs.

http://java.sun.com/j2se/1.3/docs/api/java/io/File.html

You should be able to delete a file or directory with the "delete" method.
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 50 total points
ID: 7121885
I found this in a FAQ:

public void nuke(File path)
   throws IOException
{
   File[] files = path.listFiles();

   for(int i=0; i<files.length; ++i)
   {
      if(files[i].isDirectory())
         nuke(files[i]);

      files[i].delete();
   }
}

its pretty much a recursive method that will delete a directory and all its files and sub-dirs.

call it using:
nuke("/path/to/dir/to/delete");

HTH,
CJ
0
 

Author Comment

by:trowa
ID: 7126368
CJ, thanks again. The nuke function above work well, but it didn't delete the folder itself. Let's say:

i call nuke("\a");

all the sub-folder and files in a folder is deleted, but the a folder itself is not deleted.

Maybe you can show me how to delete the a folder also inside the Nuke function above.

and why when i compare a String value, i must use:

if (strvalue.equals("abc")) {
//
}

but not if (strvalue == "abc") {
//
}

?

Is this the syntax of Java? what's their difference?

Thanks :)
0
Technology Partners: 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!

 
LVL 19

Expert Comment

by:cheekycj
ID: 7127040
you can just after you call the nuke function do this:

nuke(path);
File dirToDelete = new File(path);
path.delete();

string1.equals(string2) or even
string1.equalsIgnoreCase(string2) are the way to compare strings in java b/c the String object has those methods implemented to compare the values whereas the "==" operator on Objects (Strings are Objects) compares if the two objects are pointing to the same memory reference.  Big Difference :-)

Here is a good link that explains this:
http://www.michael-thomas.com/java/javacert/JCP_ObjectEqual.htm

HTH,
CJ

0
 

Author Comment

by:trowa
ID: 7131361
Thanks a lot again, CJ :)
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7131762
Glad I could help and Thanx for the "A".

CJ
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Display current date,month,and year to JTextField 3 63
maven project in eclipse 11 60
struts spring hibernate example 12 136
How  can  i  resolve  HTTP Status 404 -? 8 58
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question