根据html模板动态生成html

public class GeneratingHTML {

    /**
     * 读取HTML文件
     *@param filePath
     *@return
     */
    public static String retrieveHtmlFile(String filePath) { 
        File file = new File(filePath);  
        InputStream input = null;
    try {
         input = new FileInputStream(file);
    } catch (FileNotFoundException e) {
         e.printStackTrace();
    }  
        StringBuffer buffer = new StringBuffer();  
        byte[] bytes = new byte[1024];
        try {
             for(int n ; (n = input.read(bytes))!=-1 ; ){  
                   buffer.append(new String(bytes,0,n,"GBK"));  
             }
        } catch (IOException e) {
                 e.printStackTrace();
        }
        return buffer.toString();  
    }  
    
    /**
     * 上传HTML文件
     *@param filePath
     *@return
     * @throws IOException 
     */
    public static String uploadHtmlFile(String html,String url,String path) throws IOException {
    String fileame = + "test.html";
url = url + fileame;
         FileOutputStream fileoutputstream = new FileOutputStream(path + url);// 建立文件输出流
         byte tag_bytes[] = html.getBytes();
         fileoutputstream.write(tag_bytes);
         fileoutputstream.close();
    return url;
    } 
    
}

猜你喜欢

转载自blog.csdn.net/charlene717/article/details/79991553