zoukankan      html  css  js  c++  java
  • 用jsp,读远程文件,保存到本地

    用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);
    这一段是如果你的机器设定了防火墙,需要加上,如果是直接连上网,就不用。

  • 相关阅读:
    修改BeEF工具默认密码
    Metasploit发布了新版本5.0.83
    抓包概念大比较:数据报、数据包、分组
    Metasploit reload命令使用技巧
    Metasploit设置VERBOSE参数技巧
    了解 JavaScript (3)- 马上开始
    了解 JavaScript (2)- 需要了解的一些概念
    了解JavaScript(1)- Hello World
    ASP入门(二十三)- 数据库插入、更新和删除操作
    ASP入门(二十二)-连接数据库
  • 原文地址:https://www.cnblogs.com/zyxzhsh/p/1894075.html
Copyright © 2011-2022 走看看