/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package url3_getcontent;
import java.net.*;
import java.io.*;
/**
*
* @author QiuLin
*/
public class getContent {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try{
//创建一个URL对象
URL url=new URL("http://www.baidu.com/");
//获取该URL地址下的内容
Object content=url.getContent();
String text;
//Image img;
//if(content instanceof String){
text=(String)content;
/*{
else if(content instanceof Image){
img=(image)content;
}*/
System.out.println(text);
}catch(MalformedURLException me){
System.out.println("MalformedURLException :"+me);
}catch(IOException ioe){
System.out.println("IOException :"+ioe);
}
}
}
评论1
最新资源