Directory Processing Tool class Dealwithdir.java

Source: Internet
Author: User

  1. Package com.util;
  2. Import Java.io.File;
  3. /**
  4. * Directory Processing Tool class
  5. *
  6. */
  7. Public class Dealwithdir {
  8. /** 
  9. * New Directory
  10. */
  11. public Static boolean newdir (String path) throws Exception {
  12. File File = new file (path);
  13. return File.mkdirs (); //Create a directory
  14. }
  15. /** 
  16. * Delete Directory
  17. */
  18. public Static boolean deletedir (String path) throws Exception {
  19. File File = new file (path);
  20. if (!file.exists ())
  21. return false; Directory does not exist exit
  22. if (File.isfile ()) //If the file is deleted
  23. {
  24. File.delete ();
  25. return false;
  26. }
  27. file[] files = file.listfiles (); //If files are deleted recursively in the directory
  28. For (int i = 0; i < files.length; i++) {
  29. Deletedir (Files[i].getabsolutepath ());
  30. }
  31. File.delete ();
  32. return File.delete (); //delete directory
  33. }
  34. /** 
  35. * Update Catalog
  36. */
  37. public Static boolean Updatedir (string path, string NewPath) throws Exception {
  38. File File = new file (path);
  39. File NewFile = new File (NewPath);
  40. return File.renameto (newFile);
  41. }
  42. public static void Main (String d[]) throws exception{
  43. //deletedir ("D:/ff/dddf");
  44. Updatedir ("D:\\tools\\tomcat 6.0\\webapps\\bcccsm\\nationalexperiment/22222", "D:\\tools\\tomcat 6.0\\  Webapps\\bcccsm\\nationalexperiment/224222 ");
  45. }
  46. }

Directory Processing Tool class Dealwithdir.java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.