Java 19-15 file class How to change file names in bulk

Source: Internet
Author: User

1 /*2      Requirements :
* Change the name of the video below H:\ kingdoms to3 00?_ Introduction. avi4 5    Ideas:6 A: Package directory7 B: Gets the file array for all files in this directory8 C: Traverse the file array to get each file object9 D: Stitch A new name, then rename it. Ten */ One PackageZl_file; A - ImportJava.io.File; - Public classFileTest3 { the - Public Static voidMain (string[] args) { - - //Package Catalog +File Forder =NewFile ("H:\\ Kingdoms"); - + //get file array for all files in this directory Afile[] FileList =forder.listfiles (); at - //iterate over the file array to get each file object - for(File file:filelist) { - //Kingdoms _001_[Storytelling net]_ Taoyuan three jieyi. avi changed to 001_ Taoyuan three jieyi. avi - //first get the name -String name =file.getname (); in //intercept the part of the name that you want to modify - //First Intercept ' 001 ' out, and its left is _, and then intercept 3 characters from _ to //index position of first fetch _ + intIndex1 = Name.indexof ("_"); -String newname1 = name.substring (index1 + 1, index1+4);//package left without packet right the //System.out.println (newname1); * $ //then intercept ' Taoyuan three jieyi. avi ' OutPanax Notoginseng intIndex2 = Name.lastindexof ("_"); -String newname2 = name.substring (INDEX2);//from _ To the end, intercept it. the + //Stitching AString result =Newname1.concat (newname2); the System.out.println (result); + /* - 001_ Taoyuan three jieyi. avi $ 002_ 10 The usual mess of the waiter. avi $ 003_ in the Battle of Lu bu. avi - The Battle of 004_ Chibi. avi - */ the } - Wuyi the } -}

Java 19-15 file class How to change file names in bulk

Related Article

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.