URLConnection getURL() in Java

getURL(): This method is available in the java.net.URLConnection class of Java.

Syntax:

URL java.net.URLConnection.getURL()

This method returns the value of this URLConnection's URL field.

Parameters: NA

Returns: the value of this URLConnection's URL field.

Exceptions: NA

Approach

Java

package com.URLConnection;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

public class URLConnectiongetURL {
    public static void main(String[] args) throws IOException {

        URL url = new URL("https://beingcodeexpert.blogspot.com/");
        URLConnection urlConnection = url.openConnection();

        System.out.println(urlConnection.getURL());
    }
}

Output:

https://beingcodeexpert.blogspot.com/


Some other methods of URLConnection class

addRequestProperty(String, String)This method adds a general request property specified by a key-value pair.

connect()This method opens a communications link to the resource referenced by this URL if such a connection has not already been established.

getAllowUserInteraction()This method returns the value of the allowUserInteraction field for this object.

getConnectTimeout()This method returns the setting for connect timeout.

getContent()This method retrieves the contents of this URL connection.

getContent(Class<?>[]) This method retrieves the contents of this URL connection.

getContentEncoding()This method returns the value of the content-encoding header field.

getContentLength()This method returns the value of the content-length header field.

getContentLengthLong()This method returns the value of the content-length header field as long.

getContentType()This method returns the value of the content-type header field.

getDate()This method returns the value of the Date header field.

URLConnection.getDefaultAllowUserInteraction()This method returns the default value of the allowUserInteractionfield.

getDefaultUseCaches()This method returns the default value of a URLConnection's useCaches flag.

URLConnection.getDefaultUseCaches(String)This method returns the default value of the useCaches flag for the given protocol.

getDoInput()This method returns the value of this URLConnection's input flag.

getDoOutput()This method returns the value of this URLConnection's output flag.

getExpiration()This method returns the value of the expires header field.

URLConnection.getFileNameMap()This method loads a filename map (a mimetable) from a data file.

getHeaderField(int)This method returns the value for the nth header field. It returns null if there are fewer than n+1 fields.

getHeaderField(String)This method returns the value of the named header field.

getHeaderFieldDate(String, long)This method returns the value of the named field parsed as a date.

getHeaderFieldInt(String, int)This method returns the value of the named field parsed as a number.

getHeaderFieldKey(int)This method returns the key for the nth header field. 

getHeaderFieldLong(String, long)This method returns the value of the named field parsed as a number.

getHeaderFields()This method returns an unmodifiable Map of the header fields.

getIfModifiedSince()This method returns the value of this object's ifModifiedSince field.

getInputStream()This method returns an input stream that reads from this open connection.

getLastModified()This method returns the value of the last-modified header field. 

getOutputStream()This method returns an output stream that writes to this connection.

getPermission()This method returns a permission object representing the permission necessary to make the connection represented by this object.

getReadTimeout()This method returns a setting for read timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).

getRequestProperties()This method returns an unmodifiable Map of general request properties for this connection.

getRequestProperty(String)This method returns the value of the named general request property for this connection.

getURL()This method returns the value of this URLConnection's URL field.

getUseCaches()This method returns the value of this URLConnection's useCaches field.

URLConnection.guessContentTypeFromName(String)This method tries to determine the content type of an object, based on the specified  "file" component of a URL.

URLConnection.guessContentTypeFromStream(InputStream)This method tries to determine the type of input stream based on the characters at the beginning of the input stream.

setAllowUserInteraction(boolean)This method set the value of the allowUserInteraction field of this URLConnection.

setConnectTimeout(int)This method sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.

URLConnection.setContentHandlerFactory(ContentHandlerFactory)This method sets the ContentHandlerFactory of an application. It can be called at most once by an application.

setDefaultUseCaches(boolean)This method sets the default value of the useCaches field to the specified value.

setDefaultUseCaches(String, boolean)This method sets the default value of the useCaches field for the named protocol to the given value.

setDoInput(boolean)This method sets the value of the doInput field for this URLConnection to the specified value.

setDoOutput(boolean)This method sets the value of the doOutput field for this URLConnection to the specified value.

URLConnection.setFileNameMap(FileNameMap):  This method sets the FileNameMap.

setIfModifiedSince(long)This method sets the value of the ifModifiedSince field of this URLConnection to the specified value.

setReadTimeout(int)This method sets the read timeout to a specified timeout, in milliseconds.

setRequestProperty(String, String)This method sets the general request property. If a property with the key already exists, overwrite its value with the new value.

setUseCaches(boolean)This method sets the value of the useCaches field of this URLConnection to the specified value.

toString()This method returns a String representation of this URL connection.

No comments:

Post a Comment