您的位置:首页 > 其它

区分activity的四种加载模式

2015-10-29 14:42 411 查看
public static void generatorHtml() {
String html = "";
String filePath = ServletActionContext.getServletContext().getRealPath(
"/index.html");
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
try {
HttpServletRequest request = ServletActionContext.getRequest();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort();
URL url = new URL(basePath + "/index_doQuery.do");
URLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

uc.setConnectTimeout(3000);
InputStream in = uc.getInputStream();

int n;
StringBuffer buffer = new StringBuffer();

BufferedReader reader = new BufferedReader(new InputStreamReader(
in, "utf-8"));
while ((n = reader.read()) != -1) {
buffer.append((char) n);
}
html = new String(buffer.toString());

file.createNewFile();
FileOutputStream o = new FileOutputStream(filePath);
o.write(html.getBytes("UTF-8"));
} catch (IOException e) {

e.printStackTrace();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: