全部博文(42)
分类: Java
2008-05-03 21:23:30
package test;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
/**
* 写了个和php的 file_get_contents(""); 一样的功能的东东
*
* @author 流水孟春
*/
public class F {
public static void main(String[] args) throws Exception {
String url = "";
URL resource = null;
HttpURLConnection httpUrl = null;
BufferedInputStream bis = null;
resource = new URL(url);
httpUrl = (HttpURLConnection) resource.openConnection();
httpUrl.connect();
StringBuffer sb = new StringBuffer();
BufferedReader in = null;
in = new BufferedReader(new InputStreamReader(httpUrl.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
String str = new String(sb.toString().getBytes(), "utf-8");
System.out.println(str);
httpUrl.disconnect();
bis = null;
httpUrl = null;
resource = null;
}
}