import java.io.DataInputStream; import java.net.URL; import java.net.URLConnection; public class ReadURLConnection { /** * @param URLConnection类 */ public static void main(String[] args) { try { //创建URL对象 URL cumtURL = new URL("http://www.xiaonei.com"); //创建链接对象 URLConnection cumtConnection = cumtURL.openConnection(); //获取URLConnection的数据输入流 DataInputStream dataInputStream = new DataInputStream(cumtConnection.getInputStream()); String inputLine; while((inputLine=dataInputStream.readLine())!=null){ System.out.println(inputLine); } dataInputStream.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
四.URLConnection类读取URL对象内容
最新推荐文章于 2019-07-23 14:44:40 发布