Java version of delete files named "xxx.txt" file name under the specified directory

Source: Internet
Author: User

A python version was previously written, but an error occurred while locating the file path, and the path to the file could not be obtained correctly, resulting in the inability to delete the "xxx.txt" file under the path.

At that time thought is the Windows version system error caused this problem, also did not continue to delve into, the bug to let go.

Recent period of time in the study of Android, definitely to use the Java, the implementation of Java, the idea of the words, definitely or before, the result is still wrong, and then carefully looked at the code, is actually their own bug.

Paste the code: (main function, delete all files named "Pylist.txt" under the specified directory, using recursion and file Class)

1 ImportJava.io.File;2 3  Public classExample826 {4      Public Static voidMain (string[] args) {5String dir = "D:\\pcsync\\python";6 Circlemethod (dir);7     }8 9     Private Static voidCirclemethod (String dirpath) {TenFile File =NewFile (dirpath); One         if(File.isdirectory ()) { Astring[] Dirpathlist =file.list (); -              for(inti = 0; i < dirpathlist.length; i++) { -String FilePath = Dirpath + File.separator +Dirpathlist[i];
15
-File Filedelete =NewFile (filePath); - if(Filedelete.getname (). Equals ("Pylist.txt")) { - Filedelete.delete (); + } - Circlemethod (FilePath); Recursive + } A } at } - -}

Java version of delete files named "xxx.txt" file name under the specified directory

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.