zoukankan      html  css  js  c++  java
  • 生成静态页java代码


    package com.fang.news.test;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    
    /**   
     *    
     * 项目名称:NewsPortalProject   
     * 类名称:HTMLMaker   
     * 类描写叙述:   
     * 创建人:XianJuanJuan   
     * 创建时间:2015年7月23日 下午5:34:02    
     * @version    
     *    
     */
    public class HTMLMaker {
    	
    	final static Object lock = new Object();   
    	public static void makeHtml(String page, String filePath){   
    		makeHtml(page,filePath,"utf-8");   
    	 }   
    
    	public static void main(String[] args) {
    		
    		String page = "http://bj.58.com/";
    		String filePath = "D://test.html";
    		makeHtml(page, filePath);
    	}
    	 public static void makeHtml(String page, String filePath,String chartset) {   
    	  synchronized (lock) {
    		    
    		  HttpURLConnection huc = null;   
    		  BufferedReader br = null;   
    		  BufferedWriter bw = null;   
    		  try {   
    			  huc = (HttpURLConnection)new URL(page).openConnection();   
    			  System.setProperty("sun.net.client.defaultConnectTimeout", "30000");   
    			  System.setProperty("sun.net.client.defaultReadTimeout", "30000");    
    			  huc.connect();   
    			  InputStream stream = huc.getInputStream();   
    			  bw = new BufferedWriter(new OutputStreamWriter (new FileOutputStream(filePath),chartset));   
    			  br = new BufferedReader(new InputStreamReader(stream, chartset));   
    			  String line;   
    			  while((line = br.readLine())!= null){   
    				  if(line.trim().length() > 0){   
    					  bw.write(line);   
    					  bw.newLine();   
    				  }   
    			  }   
    		  } catch (Exception e) {   
    			  e.printStackTrace();   
    		  } finally {   
    			  try {   
    				  br.close();   
    				  bw.close();   
    				  huc.disconnect();   
    			  } catch (Exception e) {   
    				  e.printStackTrace();   
    			  }   
    		  }    
    	  	}   
    	 }
    }
    


  • 相关阅读:
    UIButton和UIImageView的区别
    大道至简第八章读后感
    简单登录界面
    大道至简第七章读后感
    计算成绩代码
    大道至简第六章读后感
    产生随机数代码
    大道至简第五章读后感
    计算成绩算法
    加密算法
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6930725.html
Copyright © 2011-2022 走看看