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){


本文标签: 失败 系统 路径