import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
public class URLTest {
//抽取股票信息字符串
public static void main(String[] args) {
String result = null;
try {
URL u = new URL("http://www.baidu.com");
byte[] b = new byte[256];
InputStream in = null;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
try {
in = u.openStream();
int i;
while ((i = in.read(b)) != -1) {
bo.write(b, 0, i);
}
result = bo.toString();
bo.reset();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (in != null) {
in.close();
}
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
System.out.println("result:" + result);
}
}
import java.io.InputStream;
import java.net.URL;
public class URLTest {
//抽取股票信息字符串
public static void main(String[] args) {
String result = null;
try {
URL u = new URL("http://www.baidu.com");
byte[] b = new byte[256];
InputStream in = null;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
try {
in = u.openStream();
int i;
while ((i = in.read(b)) != -1) {
bo.write(b, 0, i);
}
result = bo.toString();
bo.reset();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (in != null) {
in.close();
}
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
System.out.println("result:" + result);
}
}