public class Url {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:8081/qinjiang/hanbin.txt");
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("hanbin.txt");
byte[] buffer = new byte[1024];
int len;
while((len = inputStream.read(buffer))!=-1){
fos.write(buffer,0,len);//写出这个资源
}
fos.close();
inputStream.close();
urlConnection.disconnect();
}
}
首先先开启Tomcat才行