Đang chuẩn bị liên kết để tải về tài liệu:
Lecture 9: Network programming

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet. Sample structure of a URL. The resource name part may contain: host name, file | Lecture 9: Network programming Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet. Sample structure of a URL. The resource name part may contain: host name, file name, port number(optional) and reference (optional) http://java.sun.com you can create a URL object in Java from an absolute URL or a relative URL. The URL class provides several methods implemented on URL objects. You can get the protocol, host name, port number, and filename from a URL. Protocol Identifier Resource Name Example code import java.net.*; import java.io.*; public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new URL("http://java.sun.com:80/docs/books/" + "tutorial/index.html#DOWNLOADING"); System.out.println("protocol = " + aURL.getProtocol()); System.out.println("host = " + aURL.getHost()); System.out.println("filename = " + aURL.getFile()); System.out.println("port = " + aURL.getPort()); System.out.println("ref = " + aURL.getRef()); } } Output of the above code: protocol = http host = java.sun.com filename = /docs/books/tutorial/index.html port = 80 ref = DOWNLOADING Connecting with a URL (1) openStream(): returns a java.io.InputStream object, from which you can read easily as reading from an input stream. It may throw an IOException Example code import java.net.*; import java.io.*; public class ReadURL { public static void main(String[] args) throws Exception { URL osu = new URL("http://www.itu.edu/"); BufferedReader in = new BufferedReader( new InputStreamReader(osu.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } } This prints out the source code for the webpage www.itu.edu Connecting with a URL (2) openConnection(): Returns a URLConnection object that represents a connection to the remote object referred to by the URL. It may throws an IOException try { URL osu = new . | Lecture 9: Network programming Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet. Sample structure of a URL. The resource name part may contain: host name, file name, port number(optional) and reference (optional) http://java.sun.com you can create a URL object in Java from an absolute URL or a relative URL. The URL class provides several methods implemented on URL objects. You can get the protocol, host name, port number, and filename from a URL. Protocol Identifier Resource Name Example code import java.net.*; import java.io.*; public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new URL("http://java.sun.com:80/docs/books/" + "tutorial/index.html#DOWNLOADING"); System.out.println("protocol = " + aURL.getProtocol()); System.out.println("host = " + aURL.getHost()); System.out.println("filename = " + aURL.getFile()); System.out.println("port = " + aURL.getPort()); .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.