Put your text ad here
WestNIC provides reliable web hosting services
Free software downloads and drivers download resources
Top Canadian Hotels no booking fees from Victoria BC to Nova Scotia
This FAQ is part of the Code Style Help and FAQ section. Join our premium content service for full access all FAQ answers.
A: The standard Java input/output and network APIs make it quite easy to acquire content from the Internet and write files. Writing from a stream input to a file output is the slightly complex part. The example below uses a copy(InputStream, OutputStream) method adapted from a version in Java I/O by Elliotte Rusty Harold.
… premium content omitted
Get full access to all FAQs, sign-up, name your price
How can I download a Web page and write it to a file?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: Many Web sites use virtual hosting, which requires you send an HTTP Host header with your request.
… premium content omitted
Get full access to all FAQs, sign-up, name your price
My Java Web client gets the wrong site!
Actions: Follow-up, clarify or correct this answer. Submit a new question.
Your application should pass a User-Agent header in the HTTP request with the code name of your application as the header value. Web browser user agents often include the full version and build number for the application and the software platform it was built for. Feed readers tend to use simpler name and version number combination. See the Java example below.
… premium content omitted
Get full access to all FAQs, sign-up, name your price
How can I set a code name identifier for my feed reader?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: If you want to extract a domain name from an existing URL object, use the URL's getHost() method.
String urlString = "http://www.test.example/path/page.htm";
URL url = new URL(urlString);
String domain = url.getHost();
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: The URL getHost() method returns the fully qualified domain name (FQDN). To get the registered domain name you would need to break the FQDN further to remove any subdomains. The example below uses the String lastIndexOf() method to get the index of the dot separators and substring() to extract codestyle.org from www.codestyle.org.
… premium content omitted
Get full access to all FAQs, sign-up, name your price
How do I get the registered domain name from a URL?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: It is possible to do a reverse name look-up for an IP address using the java.net.InetAddress class. The example below first gets an instance of the class using the static getByName(String) method, then applies the getHostName() method to it. The method will only resolve a domain name if there is one configured for the host, otherwise the method returns the original IP address.
… premium content omitted
Get full access to all FAQs, sign-up, name your price
How do I get a domain name from an IP address?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
| Front-end FAQs | Back-end FAQs | Learning Java |
|---|---|---|
About us: site help, text ads, sponsored links and premium content FAQs.