java 写入网页内容

java写入网页内容

public static boolean writeHtml(String htmlPath,String htmlContent) throws IOException {
    File newFile = new File(htmlPath);
    //自动创建目录
    File parentPath = new File(newFile.getParent());
    if(!parentPath.exists()) {
        parentPath.mkdirs();
    }
    FileWriter fileWriterObj = new FileWriter(newFile);
    BufferedWriter bufferedWriterObj = new BufferedWriter(fileWriterObj);
    bufferedWriterObj.write(htmlContent+"\n");
    bufferedWriterObj.flush();
    bufferedWriterObj.close();
    fileWriterObj.close();
    
    return true;
}

 

 

 

#########################

posted @ 2022-12-11 16:04  西北逍遥  阅读(89)  评论(0编辑  收藏  举报