Java 得到HTML源码

阅读更多

package bebo.app.core;

import java.io.*;
import java.net.*;
public class test {
                public static void main(String args[]){
                  try{
                   URL u=new URL("http://www.bebo.com/c/apps/browse_apps?sort=AZ");
                   URLConnection uc=u.openConnection();
                   InputStream raw=uc.getInputStream();
                   InputStream buffer=new BufferedInputStream(raw);
                   //
                   Reader r=new InputStreamReader(buffer);
                   int c;
                   while((c=r.read())!=-1){
                          System.out.print((char) c);
                        } //end while
                  }//end try
                //catch (MalformedURLConnection e){
                //      System.err.println("cannot connect");
                //      }
                catch (IOException e){
                         System.err.println(e);
                        }// end catch
        }// end main
}//end test

你可能感兴趣的:(Java,HTML,C,C++,C#)