import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Pattern;
public class HtmlFormWorkCopier {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.println("请输入文件名:");
String fn=scan.next();
String pattern=".*\\.html";
if(!Pattern.matches(pattern,fn)) {
fn+=".html";
};
File file=new File(fn);
if(file.exists()) {
System.out.println("文件已经存在,是否覆盖?(yes/no):");
String check=scan.next().toLowerCase();
if(check!="y"&&check!="yes") {
return;
}
}
file.createNewFile();
System.out.println("文件创建成功!");
FileWriter fw=new FileWriter(file);
String content="<!DOCTYPE html>\r\n" +
"<html lang=\"en\">\r\n" +
"<head>\r\n" +
" <meta charset=\"UTF-8\">\r\n" +
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n" +
" <title>Document</title>\r\n" +
"</head>\r\n" +
"<body>\r\n" +
" \r\n" +
"</body>\r\n" +
"</html>";
fw.write(content);
System.out.println("模板写入成功!");
fw.close();
}
}
html模板创建者
最新推荐文章于 2024-01-14 15:52:39 发布