import java.io.IOException;
import java.net.URL;
import java.net.UnknownHostException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author vlinux
*/
public class HelpA {
/** Creates a new instance of HelpA */
public HelpA() {
try {
URL url = new URL("http://www.csdn.net/");
//程序暂停5秒让你断开网络
//如果你在此其间断掉网路,
//那么将会抛出UnknownHostException异常
try {
Thread.sleep(1000*5);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
//假设的工作
BufferedReader br =
new BufferedReader(new InputStreamReader(url.openStream()));
while( br.ready() ) {
System.out.println(br.readLine());
}
br.close();
} catch (UnknownHostException ex) {
ex.printStackTrace();
//如果网络断开则会出现UnknownHostException异常
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static void main(String... args) {
new HelpA();
}
}
[此贴子已经被作者于2007-2-14 10:31:43编辑过]