package com.hyq.src;
import java.io.inputstream;
import java.net.url;
public class test {
/**
* @param args
*/
public static void main(string[] args) {
try{
test.testnetstream();
}catch(exception e){
e.printstacktrace();
}
}
public static void testnetstream()throws exception{
url url=new url("http://www.imust.cn/");
inputstream in=url.openstream();
byte[] b=new byte[100000];
in.read(b);
in.close();
string s=new string(b);
system.out.println(s);
}
}
package com.hyq.src;
import java.io.bufferedreader;
import java.io.inputstreamreader;
import java.net.url;
import java.net.urlconnection;
public class test {
public static void main(string[] args)
{
system.out.println(test.gethtmlsource("http://sports.163.com/zc/"));
}
public static string gethtmlsource(string url){
stringbuffer stb=new stringbuffer();
try{
urlconnection uc=new url(url).openconnection();
bufferedreader br=new bufferedreader(new inputstreamreader(uc.getinputstream(),"gb2312"));
string temp=null;
while((temp=br.readline())!=null){
stb.append(temp).append("\n");
}
br.close();
}catch(exception e){
e.printstacktrace();
}
return stb.tostring();
}
}