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 handle cookies using Jakarta Servlet API? - April 19, 2025
- How do I set response headers with HttpServletResponse? - April 18, 2025
- How do I apply gain and balance using FloatControl? - April 18, 2025