恳请高手帮个忙!

来源:百度知道 编辑:UC知道 时间:2024/05/28 19:00:38
import java.net.*;

public class Net {

public static void main(String[] args) {
try {
URL url = new URL("http://www.ustb.edu.cn/");
} catch (MalformedURLException e) {System.out.println("错误!");}
System.out.println(url.) //为什么总是显示无法识别url,这个没错吧!
}

}

你声明URL url是在try里面声明的,出了try catch这个变量就销毁了,所以是不能输出的
URL url=null;
try {
url = new URL("http://www.ustb.edu.cn/");
} catch (MalformedURLException e) {System.out.println("错误!");}
System.out.println(url.toString());
这样就可以了,祝你进步

什么东西?