You can use the File class to batch Delete duplicate files in a File, for example, haokan (22.16.mp4, haokan (32.16.mp4,

Source: Internet
Author: User

You can use the File class to batch Delete duplicate files in a File, for example, haokan (22.16.mp4, haokan (32.16.mp4,

1 public class HH {2 public static void main (String [] args) {3 String s = "he is a boy"; 4 int result = s. indexOf ("boy ");

I am using the indexOf () method;
5 if (result> = 0) {6 System. out. println ("boy is part of he is a boy"); 7} else {8 System. out. println ("boy is not part of he is a boy"); 9} 10} 11}

In fact, this is an online method. I was wondering if I could use character matching, but matches () is not very useful yet, so I came up with a good method;

Based on the above Code!

File file = new File("d:/");

Defines the file path;

1 File file = new File ("E:/thunder download/videos"); 2 3 File [] file2 = file. listFiles (new FileFilter () {4 // here, an array of files 5 @ Override 6 public boolean accept (File path) {7 int result = path. getName (). indexOf ("(5 )");
// Here, IndexOf () gets the position (5) and returns its position. If there is a value greater than 0
8 int result2 = path. getName (). indexOf ("(6)"); 9 int result3 = path. getName (). indexOf ("(7)"); 10 if (result> 0 | result2> 0 | result3> 0) {11 return true; 12} 13 return false; 14}
15 });
     for (File file3 : file2) {            file3.delete();            //System.out.println(file3.getName());        }

 

This is my method, which is very troublesome.

Later, I asked my mentor about his method;

 

1 File [] files = folder. listFiles (new FileFilter () {2 3 @ Override 4 public boolean accept (File path) {5 if (path. getName (). matches (". * \ ([1-9] \). *")){


\ (= (Here the escape character is used


6 return true; 7} 8 return false; 9} 10 });

This is the String. matches () matching method;

 

 

 

 

 

This is a small program and I hope to share it with you.

Summary

The above explains the simple use of file matching, although it is only an auxiliary function,

Please support originality and respect originality. Please indicate the source for reprinting. Thank you.

 

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.