Java modifies the names of multiple files

Source: Internet
Author: User

It's three steps, actually.

The first one to put the required file type, what file to find

File2.getname (). EndsWith (". txt")  can determine what file to use with the suffix of the. txt name

Step Two

File File1 = new file ("Ceshi2", File2.getname ());   Initialize the required files
File File3 = new file ("Ceshi2", "Oracle" +File2.getname ());   Initialize the name of the file I want to modify

Step Three

Use Renameto to modify so that all the file names are modified.

 PackageCn.oracle.file1;/*** Change the name of multiple files*/ImportJava.io.File; Public classFile2 { Public Static voidMain (string[] args) {//Initialize Find folderFile File =NewFile ("Ceshi2"); //return the contents of the folderfile[] Listfiles =File.listfiles (); //Traverse out         for(File file2:listfiles) {//Find File            if(File2.getname (). EndsWith (". txt")) {//Print to seeSystem.out.println (File2.getname ()); //Initialize the required filesFile file1 =NewFile ("Ceshi2", File2.getname ()); //Initialize the name of the file I want to modifyFile File3 =NewFile ("Ceshi2", "Oracle" +file2.getname ()); //ModifyFile1.renameto (FILE3); }        }            }}

Java modifies the names of multiple files

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.