admin 管理员组文章数量: 1087139
2024年5月8日发(作者:开源下载系统)
import ;
import iter;
import tream;
import riter;
import LConnection;
import ;
public class HtmlPage {
public static void main(String[] args) {
// TODO Auto-generated method stub
if(saveHtmlPage( getHtmlPage("","U
TF-
8"),"F:/")){
n("生成成功");
}else{
n("生成失败");
}
if(deleteFile("F:/")){
("删除成功");
}else{
("删除失败");
}
}
/**
*
* @param httpURL 网页地址
*
* @param encode 默认为UTF-8
* @return Html 页面的代码
*/
public static String getHtmlPage(String httpURL,String
encoding){
String htmlCode="";
try {
InputStream inputStream;
URL url = new URL(httpURL);
HttpURLConnection connection =
(HttpURLConnection) nnection();
t();
inputStream = utStream();
byte bytes[] = new byte[1024 * 2000];
int index = 0;
int count = (bytes, index,
1024 * 2000);
while (count != -1) {
index += count;
count = (bytes, index,
1);
}
htmlCode = new String(bytes, encoding);
// htmlCode = new String(bytes);
nect();
} catch (Exception ex) {
tackTrace();
return null;
}
return ();
}
public static boolean saveHtmlPage(String htmlCode,String
fileName){
//String fileName="";//文件的路径包含文件名
//fileName="F:/my work/printsd/WebRoot/";
try{
File file = new File(fileName);
FileWriter resultFile = new FileWriter(file);
//PrintWriter myFile = new
PrintWriter(resultFile,"UTF-8");
PrintWriter myFile = new
PrintWriter(file,"UTF-8");
//写文件
n(htmlCode);
();
();
}catch(Exception e){
版权声明:本文标题:Java指定编码生成静态网页技术 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1715179779a686181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论