[13] socket.pdf
(
107 KB
)
Pobierz
QPrint
Klasa URL
Sockety
URL-e w Javie Î tworzenie
€
€
z
z
URL
umk =
= new
new URL("http://
URL("http://www
www.uni
uni.torun
torun.pl
pl");
");
URL (URL
URL (URL baseURL
baseURL,
, String relativeURL
String relativeURL)
z z
cc
1
URL
URL umk
umk
==
new
URL("http://
www
uni
torun
ppl
URL (URL
baseURL
,,
String relativeURL
URL-e w Javie Î wyjĢtki
€
zzc
MalformedURLExceptionzz
z z
try {
URL myURL
myURL =
= new
new URL(. . .)
URL(. . .)
} catch
catch (MalformedURLException
MalformedURLException e) {..}
e) {..}
URL-e Î analiza skþadowych
€
c
€
zcz z
c zcz
zcz c
zc
zcz
zcz c
z zz
2
try
URL
myURL
==
new
}}
}
catch
MalformedURLException
Czytanie z adresu URL
import java
java.net.*;
.net.*;
import java
java.io
io.*;
.*;
public class URLReader {
public static void main
public static void main(String
String[]
[] args
args)
) throws
throws
Exception {
URL y =
new
URL("http://
new
URL("http://www
www.yahoo
yahoo.com
com/");
/");
BufferedReader in =
new BufferedReader(
new InputStreamReader
= new BufferedReader
new BufferedReader
new InputStreamReader(y.
(y.openStream
openStream()));
()));
String inputLine;
while
while ((
((inputLine
inputLine = in.
= in.readLine
readLine()) !=
()) != null
null)
System.out
out.println
println(inputLine
inputLine);
);
in.close
close();
();
}}
URLConnection
€
c
ccz c czczz
zczzz
c
zzzccz
cczcz
zzcc
zcc
try
URL yahoo
yahoo =
= new
new URL("http://
URL("http://www
www.yahoo
yahoo.com
com/");
/");
yahoo.openConnection
openConnection();
();
} catch
catch (MalformedURLException
MalformedURLException e) {..}
e) {..}
catch (IOException
IOException e) {..}
e) {..}
}
3
import
java
import
java
iio
public class URLReader
public static void main
String
[]
args
))
Exception
URL y =
URL y = new
URL("http://
www
yahoo
com
BufferedReader in
==
new InputStreamReader
(y.
openStream
String inputLine
while
(((
inputLine
= in.
readLine
()) !=
null
System.
out
println
inputLine
));
in.
close
}}
}}}
try
try {
URL
URL
yahoo
==
new
URL("http://
www
yahoo
com
yahoo
openConnection
}
}}
catch
MalformedURLException
catch
IOException
URL Î getContent()
€
czc
zz
public final Object getContent
()
throws IOException
(()
throws IOException
zc
zc
zcc
zc
zzczc
c
throws IOException
URLConnection
€
cc
cccc
c
cc
c
c
€
zzcc
ccz
c
c
4
public final Object getContent
public final Object getContent()
URLConnection - czytanie
import java
java.net.*;
.net.*;
.*;
public class URLConnectionReader
java.io
io.*;
.*;
public class URLConnectionReader {
public static void main
public static void main(String
String[]
[] args
args)
) throws
throws
Exception {
URL y =
/");
URLConnection yc = y.openConnection();
BufferedReader in
new URL("http://
URL("http://www
www.yahoo
yahoo.com
com/");
/");
BufferedReader in =
new BufferedReader(
new InputStreamReader
= new BufferedReader
new BufferedReader
new InputStreamReader(yc.getInputStream()));
));
String inputLine;
;
while ((
((inputLine
inputLine = in.
= in.readLine
readLine()) !=
()) != null
null)
))
System.out
out.println
println(inputLine
inputLine);
));
in.close
close();
();
}
}
Adresy internetowe
€
z
czc
zcc
ccz
cz z
z
public static InetAddress getByName(String host
String host)
public static InetAddress[]
[] getAllByName(String host
String host)
public static InetAddress getLocalHost()
(()
5
import
java
import
import java
java
iio
public class URLConnectionReader
public static void main
String
[]
args
))
Exception
URL y =
URL y = new
new
URL("http://
www
yahoo
com
BufferedReader in
==
new InputStreamReader
String inputLine
;;
while
(((
inputLine
= in.
readLine
()) !=
null
)
System.
out
println
inputLine
);
in.
close
public static InetAddress
String host
public static InetAddress
[[]
String host
public static InetAddress
()
Plik z chomika:
szuro1
Inne pliki z tego folderu:
zadanie6.pdf
(223 KB)
zadanie1.pdf
(417 KB)
wyklad_1xbvasj64.pdf
(352 KB)
wyklad11.pdf
(93 KB)
udp.pdf
(342 KB)
Inne foldery tego chomika:
Ajax
Algorytmy
APLETY
Bazy danych
Dokumentacja
Zgłoś jeśli
naruszono regulamin