在我们用别的html模板做jsp项目的时候如果一次性太多的html文件,我们是不是要花费一点时间来转换格式呢?现在我公布一个完整的代码来快速转换格式
package cz.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.io.OutputStream;
public class Xiugai {
public static void changeExt(String pathName)
{
File file = new File(pathName);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++)
{
if (files[i].isDirectory())
{
changeExt(files[i].getAbsolutePath());
}
String name = files[i].getAbsolutePath();
if (name.lastIndexOf(".jsp") != -1)
{
boolean is = files[i].renameTo(new File(name.substring(0, name.lastIndexOf(".jsp"))+ ".html"));
if (is)
{
System.out.println(files[i].getAbsolutePath()+ " changed to "+ name.substring(0, name.lastIndexOf(".jsp")) + ".html");
} else
{
System.out.println("Error happend!");
}
}
}
}
public static void main(String[] args)
{
String rootPath = "F:\\Users\\Administrator\\Workspaces\\MyEclipse 10\\Helld"; // 搜索的根目录
changeExt(rootPath);
}
}
如有不懂请留言