1. 程式人生 > >根據html模板動態生成html

根據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;
    } 
    
}