String text = "字符内容";
String htmlFileName = UUIDUtil.generateUUID()+".html";
String htmlPath = imgPath+ File.separatorChar+htmlFileName;
File file2 = new File(htmlPath);
StringBuilder sb = new StringBuilder();
try {
file2.createNewFile();//创建文件
sb.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>Html Test</title></head><body>");
sb.append("<div>");
sb.append(text);
sb.append("</div>");
sb.append("</body></html>");
PrintStream printStream = new PrintStream(new FileOutputStream(file2));
printStream.println(sb.toString());//将字符串写入文件
} catch (IOException e) {
code = 0;
e.printStackTrace();
}