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 ();
}
}
}