国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

用jsp讀遠程文件,保存到本地

2024-09-05 00:19:59
字體:
來源:轉載
供稿:網友

用jsp,讀遠程文件,保存到本地

讀取網絡文件有些不一樣,我給你一個完整的代碼吧,存成jsp就可以直接運行的。
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.properties"%>
<%

//?程文件路徑
string s1 = "http://www.google.co.jp";
//本地存放路徑
string s2 = "c://test.html";

url urlfile = null;
httpurlconnection httpurl = null;
bufferedinputstream bis = null;
bufferedoutputstream bos = null;
file f = new file(s2);

//make proxy
string proxy = "192.168.224.12";
string port = "8080";
properties systemproperties = system.getproperties();
systemproperties.setproperty("http.proxyhost",proxy);
systemproperties.setproperty("http.proxyport",port);

try{
//?接指定的網??源,?取網??入流
urlfile = new url(s1);
httpurl = (httpurlconnection)urlfile.openconnection();
httpurl.connect();
bis = new bufferedinputstream(httpurl.getinputstream());
}catch(exception e){
system.out.println(e.tostring());
}

try{
bos = new bufferedoutputstream(new fileoutputstream(f));;
byte[] b = new byte[1024];
while(bis.read(b)!=-1) {
bos.write(b);

}catch(exception e){
system.out.println(e.tostring()); 
}finally{
try{
bos.flush();
bis.close();
httpurl.disconnect();
}catch(exception e){
system.out.println(e.tostring()); 
}
}
 
%>
<center>
<form name="search" action="results.jsp" method="get">
<p>
<input name="query" size="44"/>&nbsp;search criteria
</p>
<p>
<input name="maxresults" size="4" value="100"/>&nbsp;results per page&nbsp;
<input type="submit" value="search"/>
</p>
        </form>
</center>
其中
//make proxy
string proxy = "192.168.224.12";//防火墻地址
string port = "8080"; //防火墻端口
properties systemproperties = system.getproperties();
systemproperties.setproperty("http.proxyhost",proxy);
systemproperties.setproperty("http.proxyport",port);
這一段是如果你的機器設定了防火墻,需要加上,如果是直接連上網,就不用。

中國最大的web開發資源網站及技術社區,
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凤庆县| 华宁县| 怀仁县| 容城县| 三都| 尚志市| 阜城县| 巴东县| 宁海县| 益阳市| 仪陇县| 涪陵区| 潞西市| 普兰县| 扶绥县| 大庆市| 常熟市| 交城县| 田阳县| 永年县| 汶川县| 绥中县| 琼海市| 革吉县| 汉沽区| 万荣县| 游戏| 建瓯市| 洛隆县| 阳山县| 越西县| 台前县| 民权县| 曲周县| 汉源县| 玛曲县| 吐鲁番市| 新和县| 屏山县| 英超| 承德市|