String fileName = "filename.html"; StringBuilder sb = new StringBuilder(); // 使用StringBuilder 构建HTML文件 sb.append("<html>\n"); sb.append("<head>\n"); sb.append("<title>HTML File</title>\n"); sb.append("</head>\n"); sb.append("<body>\n"); sb.append("<p>Hello World!</p>\n"); sb.append("</body>\n"); sb.append("</html>\n"); // 将html文件写入磁盘指定位置 FileWriter fw = null; try { fw = new FileWriter("/home/project/taotao/html/ssd/" + fileName); fw.write(sb.toString()); } catch (IOException e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } }
java生成html文件输出到指定位置
最新推荐文章于 2024-07-17 14:02:57 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)