📄 urlclient.java
字号:
/*
* Name of the Application : URLClient.java
* Development Environment : Eclipse3.0M8
* @Version 1.0
* Describtion
*
* 1)Provide URL request
*
*
* Creation / Modification History
* wsl 19:04 06/29/2004 Creation
*
* Copyright ® 2004 www.cnlab.net
* All right reserved.
*/
package net.cnlab.wsl.testsocket.simple;
import java.io.*;
import java.net.*;
public class URLClient {
protected URLConnection connection;
public static void main(String[] args) {
URLClient client = new URLClient();
String yahoo = client.getDocumentAt("http://www.yahoo.com");
System.out.println(yahoo);
}
public String getDocumentAt(String urlString) {
StringBuffer document = new StringBuffer();
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null)
document.append(line + "\n");
reader.close();
} catch (MalformedURLException e) {
System.out.println("Unable to connect to URL: " + urlString);
} catch (IOException e) {
System.out.println("IOException when connecting to URL: " + urlString);
}
return document.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -