用java写的文件保存

来源:互联网 发布:java中http协议 编辑:程序博客网 时间:2024/05/16 12:38

最近在做一个平台整合过程, 需要把原来 动态的文章内容生成静态文件.

研究了半天,找了一个JAVA程序改了一下,就可以用啦...

<%!
public boolean downLoadFile(String urlString, String localFile) {
URL url;
byte[] buffer = new byte[512];
int size = 0;
boolean success = false;
try {
url = new URL(urlString);
BufferedInputStream stream = new BufferedInputStream(url.openStream());
FileOutputStream fos = new FileOutputStream(localFile);
while ((size = stream.read(buffer)) != -1) {
fos.write(buffer, 0, size);
}
fos.close();
stream.close();
success = true;
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return success;
}
%>

调用:

FileName=BackupPathRoot+"Articles//index.html";
 Url=basePath+"listadmin/MyCreateIndex.jsp?ID="+parID;
 isok=downLoadFile(Url,FileName);

 

原创粉丝点击