java.net.URL的简单使用
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class UseUrl {
public static void main(String args[]) throws IOException {
URL url = new URL("http://234390216.iteye.com/blog/1049256");
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int len = 0;
while ((len = is.read(b)) != -1) {
out.write(b, 0, len);
}
String result = out.toString("UTF-8");
out.close();
is.close();
System.out.println(result);
}
}