从JAVA程序获取WEB主机某个资源

import java.io.DataInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import java.util.List;

public class GetHtmlOverArea {

 /**
  * @param args
  * @throws IOException
  */

 public static List getRemoteXml(String strUrl) throws IOException {

  List objString = new ArrayList();
  URL url = new URL(strUrl);
  DataInputStream dis = new DataInputStream(url.openStream());
  String line;
  while ((line = dis.readLine()) != null) {
   String line1 = new String(line.getBytes("ISO8859-1"), "utf-8");
   objString.add(line1);
  }
  return objString;
 }

 public static void main(String[] args) {
  try {
   List s = getRemoteXml("http://www.google.com");
   Object[] aaa = s.toArray();
   for (int i = 0; i < aaa.length; i++) {
   String line = (String) aaa[i];
    System.out.println(line);

   }
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

你可能感兴趣的:(java,Web,.net,Google)