Use JSP to read remote files and save them to a local device
Reading network files is somewhat different. I will give you a complete code and save it as JSP to run it directly.
<% @ Page import = "Java. Io. *" %>
<% @ Page import = "java.net. *" %>
<% @ Page import = "Java. util. properties" %>
<%
//? Path
String S1 = "http://www.google.co.jp ";
// Local storage path
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 {
//? Connect to the specified network ?? Source ,? Network fetch ?? Stream entry
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>
Where
// Make proxy
String proxy = "192.168.224.12"; // firewall address
String Port = "8080"; // firewall port
Properties systemproperties = system. getproperties ();
Systemproperties. setproperty ("HTTP. proxyhost", proxy );
Systemproperties. setproperty ("HTTP. proxyport", Port );
If your machine has set a firewall, you need to add it. If you directly connect to the Internet, you don't need.