java ---输入输出流操作(代码整理)

/**
	 * 将动态页面转化为静态页面
	 * 
	 * @param u
	 * @param path
	 * @return
	 */
	public static boolean JspToHtmlByURL(String u, String path) {	
		Logger logger = Logger.getLogger(UserQestionAction.class);
		String str = "";
		@SuppressWarnings("unused")
		int HttpResult;
		try {
			URL url = new URL(u);
			URLConnection uc = url.openConnection();
			System.out.print(uc);
			InputStream is = uc.getInputStream();
			InputStreamReader isr = new InputStreamReader(is, "UTF-8");
			BufferedReader br = new BufferedReader(isr);
			
			System.out.print(br);
			while (br.ready()) {
				str += br.readLine() + "\n";
			}
			is.close();
			System.out.print(str);
			// 写入文件
			File f = new File(path);
			OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(f),"UTF-8"); 
			BufferedWriter o=new BufferedWriter(write);   
			o.write(str); 
			o.close();
			str = "";
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			logger.info(e);
			return false;
		}
	}


你可能感兴趣的:(java)