🗊Презентация 6. Java basic I/O 4. Networking

Нажмите для полного просмотра!
6. Java basic I/O 4. Networking, слайд №16. Java basic I/O 4. Networking, слайд №26. Java basic I/O 4. Networking, слайд №36. Java basic I/O 4. Networking, слайд №46. Java basic I/O 4. Networking, слайд №56. Java basic I/O 4. Networking, слайд №66. Java basic I/O 4. Networking, слайд №76. Java basic I/O 4. Networking, слайд №86. Java basic I/O 4. Networking, слайд №96. Java basic I/O 4. Networking, слайд №106. Java basic I/O 4. Networking, слайд №116. Java basic I/O 4. Networking, слайд №126. Java basic I/O 4. Networking, слайд №136. Java basic I/O 4. Networking, слайд №146. Java basic I/O 4. Networking, слайд №156. Java basic I/O 4. Networking, слайд №166. Java basic I/O 4. Networking, слайд №176. Java basic I/O 4. Networking, слайд №186. Java basic I/O 4. Networking, слайд №19

Вы можете ознакомиться и скачать презентацию на тему 6. Java basic I/O 4. Networking. Доклад-сообщение содержит 19 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





6. Basic I/O
4. Networking
Описание слайда:
6. Basic I/O 4. Networking

Слайд 2





What Is a URL?
URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet
A URL has two main components:
Protocol identifier: For the URL http://example.com, the protocol identifier is http.
Resource name: For the URL http://example.com, the resource name is example.com.
Описание слайда:
What Is a URL? URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet A URL has two main components: Protocol identifier: For the URL http://example.com, the protocol identifier is http. Resource name: For the URL http://example.com, the resource name is example.com.

Слайд 3





Creating a URL
The easiest way to create a URL object is from a String:
    URL myURL = new URL("http://example.com/");
The URL object created above represents an absolute URL 
An absolute URL contains all of the information necessary to reach the resource in question
Описание слайда:
Creating a URL The easiest way to create a URL object is from a String: URL myURL = new URL("http://example.com/"); The URL object created above represents an absolute URL An absolute URL contains all of the information necessary to reach the resource in question

Слайд 4





Creating a URL Relative to Another
A relative URL contains only enough information to reach the resource relative to another URL
The following code creates relative URLs:
URL myURL = new URL("http://example.com/pages/"); 
URL page1URL = new URL(myURL, "page1.html"); 
URL page2URL = new URL(myURL, "page2.html"); 
This code snippet uses the URL constructor that lets you create a URL object from another URL object (the base) and a relative URL specification
Описание слайда:
Creating a URL Relative to Another A relative URL contains only enough information to reach the resource relative to another URL The following code creates relative URLs: URL myURL = new URL("http://example.com/pages/"); URL page1URL = new URL(myURL, "page1.html"); URL page2URL = new URL(myURL, "page2.html"); This code snippet uses the URL constructor that lets you create a URL object from another URL object (the base) and a relative URL specification

Слайд 5





URL addresses with Special characters
Some URL addresses contain special characters, for example the space character. Like this:
		http://example.com/hello world/ 
To make these characters legal they need to be encoded before passing them to the URL constructor.
    URL url = new URL("http://example.com/hello%20world");
Описание слайда:
URL addresses with Special characters Some URL addresses contain special characters, for example the space character. Like this: http://example.com/hello world/ To make these characters legal they need to be encoded before passing them to the URL constructor. URL url = new URL("http://example.com/hello%20world");

Слайд 6





URI
The java.net.URI class automatically takes care of the encoding characters:
URI uri = new URI("http", "example.com", "/hello world/", "");
And then convert the URI to a URL:
			URL url = uri.toURL();
Описание слайда:
URI The java.net.URI class automatically takes care of the encoding characters: URI uri = new URI("http", "example.com", "/hello world/", ""); And then convert the URI to a URL: URL url = uri.toURL();

Слайд 7





MalformedURLException
Each of the four URL constructors throws a MalformedURLException if the arguments to the constructor refer to a null or unknown protocol:
	try { URL myURL = new URL(...); } 
	catch (MalformedURLException e) { 
    		// exception handler code here 
    }
Описание слайда:
MalformedURLException Each of the four URL constructors throws a MalformedURLException if the arguments to the constructor refer to a null or unknown protocol: try { URL myURL = new URL(...); } catch (MalformedURLException e) { // exception handler code here }

Слайд 8





Reading Directly from a URL
After you've successfully created a URL, you can call the URL's openStream() method to get a stream from which you can read the contents of the URL. 
The openStream() method returns a java.io.InputStream object, so reading from a URL is as easy as reading from an input stream.
Описание слайда:
Reading Directly from a URL After you've successfully created a URL, you can call the URL's openStream() method to get a stream from which you can read the contents of the URL. The openStream() method returns a java.io.InputStream object, so reading from a URL is as easy as reading from an input stream.

Слайд 9





Reading Example
public static void main(String[] args) throws Exception {
	URL oracle = new URL("http://www.oracle.com/"); 
	BufferedReader in = new BufferedReader( new
		 InputStreamReader(oracle.openStream())); 
	String inputLine; 
	while ((inputLine = in.readLine()) != null) 
		System.out.println(inputLine); 
	in.close(); 
}
Описание слайда:
Reading Example public static void main(String[] args) throws Exception { URL oracle = new URL("http://www.oracle.com/"); BufferedReader in = new BufferedReader( new InputStreamReader(oracle.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }

Слайд 10





Connecting to a URL
URL object's openConnection method allows to get a URLConnection object for a communication link between your Java program and the URL 
URLConnection has a set of protocol specific subclasses,e.g. java.net.HttpURLConnection
Описание слайда:
Connecting to a URL URL object's openConnection method allows to get a URLConnection object for a communication link between your Java program and the URL URLConnection has a set of protocol specific subclasses,e.g. java.net.HttpURLConnection

Слайд 11





Open Connection Example
try { 
	URL myURL = new URL("http://example.com/"); 
	URLConnection myURLConnection = 				myURL.openConnection(); 
	myURLConnection.connect(); 
} 
catch (MalformedURLException e) { 
	// new URL() failed ... 
} 
catch (IOException e) { 
	// openConnection() failed ... 
}
Описание слайда:
Open Connection Example try { URL myURL = new URL("http://example.com/"); URLConnection myURLConnection = myURL.openConnection(); myURLConnection.connect(); } catch (MalformedURLException e) { // new URL() failed ... } catch (IOException e) { // openConnection() failed ... }

Слайд 12





Reading from a URLConnection
Reading from a URLConnection instead of reading directly from a URL might be more useful: you can use the URLConnection object for other tasks (like writing to the URL) at the same time.
Описание слайда:
Reading from a URLConnection Reading from a URLConnection instead of reading directly from a URL might be more useful: you can use the URLConnection object for other tasks (like writing to the URL) at the same time.

Слайд 13





Reading Example
public static void main(String[] args) throws Exception {
	 URL oracle = new URL("http://www.oracle.com/"); 
	URLConnection yc = oracle.openConnection(); 
	BufferedReader in = new BufferedReader(new 
		InputStreamReader( yc.getInputStream())); 
	String inputLine; 
	while ((inputLine = in.readLine()) != null) 
		System.out.println(inputLine); 
	in.close(); 
}
Описание слайда:
Reading Example public static void main(String[] args) throws Exception { URL oracle = new URL("http://www.oracle.com/"); URLConnection yc = oracle.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader( yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }

Слайд 14





Exercise: Read Statistics I
Read file from 
http://www.ukrstat.gov.ua/express/expr2012/09_12/234.zip
	and save it in test.zip file
Описание слайда:
Exercise: Read Statistics I Read file from http://www.ukrstat.gov.ua/express/expr2012/09_12/234.zip and save it in test.zip file

Слайд 15





Exercise: Read Statistics II
public static void main(String[] args) throws Exception{
	URL expr = new URL("http://www.ukrstat.gov.ua/express/expr2012/09_12/234.zip"); 
	URLConnection conn = expr.openConnection(); 
	InputStream in  = conn.getInputStream(); 
	FileOutputStream out = null;
Описание слайда:
Exercise: Read Statistics II public static void main(String[] args) throws Exception{ URL expr = new URL("http://www.ukrstat.gov.ua/express/expr2012/09_12/234.zip"); URLConnection conn = expr.openConnection(); InputStream in = conn.getInputStream(); FileOutputStream out = null;

Слайд 16





Exercise: Read Statistics III
	try {
		out = new FileOutputStream("test.zip");
		int c = -1;
		while ((c = in.read()) != -1) { out.write(c); } 
    } 
    finally { if (in != null)  in.close();  
        if (out != null) out.close();
        in.close();
    }
}
Описание слайда:
Exercise: Read Statistics III try { out = new FileOutputStream("test.zip"); int c = -1; while ((c = in.read()) != -1) { out.write(c); } } finally { if (in != null) in.close(); if (out != null) out.close(); in.close(); } }

Слайд 17





Exercise: Read Statistics IV
See 641GetWebFile project for the full text.
Описание слайда:
Exercise: Read Statistics IV See 641GetWebFile project for the full text.

Слайд 18





Providing Data to the Server
Create a URL.
Retrieve the URLConnection object.
Set output capability on the URLConnection.
Open a connection to the resource.
Get an output stream from the connection.
Write to the output stream.
Close the output stream.
Описание слайда:
Providing Data to the Server Create a URL. Retrieve the URLConnection object. Set output capability on the URLConnection. Open a connection to the resource. Get an output stream from the connection. Write to the output stream. Close the output stream.

Слайд 19





Manuals
http://docs.oracle.com/javase/tutorial/networking/TOC.html
Описание слайда:
Manuals http://docs.oracle.com/javase/tutorial/networking/TOC.html



Похожие презентации
Mypresentation.ru
Загрузить презентацию