java网络编程(一)
package net; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; /** * Created by hu on 2015/11/8. */ //从URL读取www网络资源 public class URLReader { public static void main(String[] args) throws Exception{ URL url=new URL("http://www.cnblogs.com/linjiqin/"); BufferedReader in=new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; while ((inputLine=in.readLine())!=null){ System.out.println(inputLine); } in.close(); } } ************************************** package net; import java.io.DataInputStream; import java.io.PrintStream; import java.net.URL; import java.net.URLConnection; /** * Created by hu on 2015/11/8. */ public class URLConn { public static void main(String[] args)throws Exception{ URL url=new URL("http://www.javasoft.com/cgi-bin/backwards"); URLConnection urlConn=url.openConnection(); DataInputStream dis=new DataInputStream(urlConn.getInputStream()); PrintStream ps=new PrintStream(urlConn.getOutputStream()); String line=dis.readLine(); ps.println(line); } }