Java IO Stream folder tool package Fileutil

Source: Internet
Author: User

http://www.verejava.com/?id=17160035681948

public class Test2 {public static void main (string[] args) {Fileutil.createdir ("dir3");        Fileutil.createdirs ("Dir4/test");        Fileutil.renamedir ("Dir4/test", "dir4/newtest");    Fileutil.deleteemptydir ("Dir3");        }}//Directory Encapsulation class import Java.io.file;public class Fileutil {//Create first level directory public static Boolean Createdir (String dirName) {        File Dir=new file (dirName);        if (!dir.exists ()) {return dir.mkdir ();    } return false;        }//create multilevel directory public static Boolean createdirs (String dirName) {file Dir=new file (dirName);        if (!dir.exists ()) {return dir.mkdirs ();    } return false;        }//Rename directory public static Boolean Renamedir (String olddir,string newdir) {file Old=new file (Olddir);        if (Old.isdirectory ()) {return Old.renameto (new File (Newdir));    } return false; }//Delete empty directory public static Boolean Deleteemptydir (String dirName) {file Dir=new file (dirName);        if (Dir.isdirectory ()) {return dir.delete ();    } return false;        }//Recursive delete directory public static void Deletedirs (String dirName) {file Dir=new file (dirName);        File[] Dirs=dir.listfiles ();            for (int i=0;dirs!=null&&i<dirs.length;i++) {File f=dirs[i];            If the file is deleted directly if (F.isfile ()) {f.delete ();            }//If the directory continues to traverse the delete if (F.isdirectory ()) {Deletedirs (F.getabsolutepath ());    }}//delete itself dir.delete (); }}

http://www.verejava.com/?id=17160035681948

Java IO Stream folder tool package Fileutil

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.