urlexam.java

来自「Java程序设计实用教程源代码 本书源代码按章分别放置在不同的文件夹中,所有程」· Java 代码 · 共 22 行

JAVA
22
字号
import java.net.*;
import java.io.*;
public class urlExam {
  public static void main(String args[]) {
    String str;
    try {
      URL url = new URL("http://www.tsinghua.edu.cn/index.htm");
      BufferedReader ins = new BufferedReader(new InputStreamReader(url.
          openStream()));
      while ( (str = ins.readLine()) != null) {
        System.out.println(str);
      }
    }
    catch (MalformedURLException e) {
      System.out.println("URL错误,请重新输入");
    }
    catch (IOException e) {
      System.out.println("输入信息时发生错误");
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?