Java common file Operations-2

Source: Internet
Author: User

The previous article documented common file operations, where files are logged under the specified path of the Linux server through the SSH server.

Third-party jar packages are used here Jsch-0.1.53.jar

1. Delete all files (including this directory) under the specified path on the server-tested, run under Linux, no problem

1 /**2 * Delete3     *@paramDST4     *@paramSftputil5     *@return6     *@authorqin_hqing7 * @date July 6, 2015 PM 4:45:318 * @comment9      */Ten     protected Static BooleanRemovefilefromssh (String DST, channelsftp chansftp) { One         BooleanBL =false; A          -         Try { - chansftp.cd (DST); the@SuppressWarnings ("Unchecked") -Vector<lsentry> v =Chansftp.ls (DST); -             if(v.size () = = 2) {//empty folder Delete directly - Chansftp.rmdir (DST); +}Else { -                 intDelsize = 0; +                  for(Iterator<lsentry> Iterator =v.iterator (); Iterator.hasnext ();) { A                      atLsentry Lsentry =(Lsentry) Iterator.next (); -String Ffname =lsentry.getfilename (); -                     if(Ffname.indexof (".") >0) {//file -CHANSFTP.RM (Ffname);//Deleting Files -}Else if(Ffname.indexof (".") = =-1) { -Removefilefromssh (dst+ffname+File.separator, chansftp); //If there is a problem with the path, try changing the file.separator to "/"  . in chansftp.cd (DST); -                     } to                      +                     if(Delsize = = V.size ()-1) {//folder still exists under current folder - removefilefromssh (DST, chansftp); the                     } *Delsize + +; $                 }Panax Notoginseng             } -              theBL =true; +}Catch(sftpexception e) { A e.printstacktrace (); the         } +          -         returnBL; $}

2, upload-tomorrow in more;-)

Java common file Operations-2

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.