package org.kodejava.net;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class URLDemo {
public static void main(String[] args) {
try {
// Creating a url object by specifying each parameter separately, including
// the protocol, hostname, port number, and the page name
URL url = new URL("https", "kodejava.org", 443, "/index.php");
// We can also specify the address in a single line
url = new URL("https://kodejava.org:443/index.php");
BufferedReader reader = new BufferedReader(
new InputStreamReader(url.openStream(), StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Latest posts by Wayan (see all)
- How do I split large excel file into multiple smaller files? - April 15, 2023
- How do I get the number of processors available to the JVM? - March 29, 2023
- How do I show Spring transaction in log / console? - March 29, 2023