使用java动态创建html页面,为什么无法读取这个文件?

使用java动态创建html页面,为什么无法读取这个文件?

package com.abbott.common.utils;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.PrintStream;

public class HtmlUtil {

public static void exportHtml() {

//用于存储html字符串

StringBuilder stringHtml = new StringBuilder();

try {

//打开文件

PrintStream printStream = new PrintStream(new FileOutputStream("./Data/test.html"));

//输入HTML文件内容

stringHtml.append("<html><head>");

stringHtml.append("<meta http-equiv="Content-Type" content="text/html; charset=GBK">");

stringHtml.append("<title>测试报告文档</title>");

stringHtml.append("</head>");

stringHtml.append("<body>");

stringHtml.append("<div>hello</div>");

stringHtml.append("</body></html>");

try{

//将HTML文件内容写入文件中

printStream.println(stringHtml.toString());

}catch (Exception e) {

e.printStackTrace();

}

} catch(FileNotFoundException e){

e.printStackTrace();

}

}

public static void main(String[] args) {

HtmlUtil.exportHtml();

}

}

os别用./这种路径,直接从System获取项目根路径,再去拼接路径!最好判断下文件是不是存在,不存在就创建文件

回答

以上是 使用java动态创建html页面,为什么无法读取这个文件? 的全部内容, 来源链接: utcz.com/a/111894.html

回到顶部