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