public static void read(File file) throws IOException {
String p = file.getPath()+"/";
String pro = ".jsp";
//判断文件夹是否存在
if(file.exists()) {
String[] fileList = file.list();
for(String filename : fileList) {
//判断是否为文件夹
File file2 = new File(p+filename);
if(file2.isDirectory()) {
read(file2);
}else {
if(filename.endsWith(".html")) {
File filehtml = new File(p+filename);
String context = "<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\"\r\n" +
" pageEncoding=\"UTF-8\"%>\r\n";
BufferedReader reader = new BufferedReader(new FileReader(filehtml));
StringBuffer con = new StringBuffer();
String c = reader.readLine();
while(c != null) {
con.append(c+"\r\n");
c = reader.readLine();
}
reader.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(filehtml));
bw.write(context+con.toString());
bw.close();
String substring = filename.substring(0,filename.indexOf("."));
filehtml.renameTo(new File(p+substring+pro));
}
}
}
}
}
public static void main(String[] args) throws IOException {
read(new File("F:\\*******后台系统管理模板html源码\\官方管理后台模板"));
}
批量修改html为jsp
最新推荐文章于 2021-10-16 00:15:12 发布