package com.具体的包明;
import java.net.URLConnection;
import java.net.URL;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
/**
* Created by IntelliJ IDEA.
* User: jiniwang
* Date: 2005-11-8
* Time: 19:52:14
* To change this template use File | Settings | File Templates.
*/
public class SnatchData {
URLConnection conn = null;
String all_content;
public String getData(String str_url) throws Exception{
try {
all_content =new String();
URL url = new URL(str_url);
conn = url.openConnection();
if (conn == null)
return null;
InputStream ins = conn.getInputStream();
ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
byte[] str_b = new byte[1024];
try {
int i = -1;
while ((i=ins.read(str_b)) > 0) {
outputstream.write(str_b,0,i);
}
all_content = outputstream.toString();
} catch (Exception ex) {
ex.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
// return new String(all_content.getBytes("ISO8859-1"));
return all_content;
}
}
调用getData(string url) 返回一个string