Java program changes the name of multiple files

Source: Internet
Author: User

Because the video tutorial name is long and long, I always want to change the video name to make it concise. However, it takes some time for manual changes, and it is uncomfortable. In order to look comfortable, I wrote a program in Java to help me change it. I tested it myself and could use it.

After the name is changed:

Program code:

Package com. XK. util;


Import java. Io. file;
Import java. Io. fileinputstream;
Import java. Io. filenotfoundexception;
Import java. Io. fileoutputstream;
Import java. Io. inputstream;
Import java. Io. outputstream;

Public class changefilesname
{
Public static void main (string [] ARGs) throws exception
{
File file = new file ("C:/CFN ");
File [] subfiles = file. listfiles ();
Inputstream is = NULL;
Byte [] buffer = NULL;

For (INT I = 0; I <subfiles. length; I ++)
{
Try
{
Is = new fileinputstream (subfiles [I]);
Int length = is. Available ();
Buffer = new byte [length];

Is. Read (buffer );


}
Catch (filenotfoundexception E1)
{
E1.printstacktrace ();
}

// Rename FN
String fn = "struts2 tutorial" + (I + 1) + ". PNG ";

System. Out. println (FN );
File file2 = new file ("C:/CFN/" + FN );
Outputstream OS = NULL;
Try
{
OS = new fileoutputstream (file2 );
OS. Write (buffer );
Is. Close ();
OS. Close ();
}
Catch (filenotfoundexception E)
{
E. printstacktrace ();
}

// Delete the previous file
Subfiles [I]. Delete ();
}

}
}

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.