Put your text ad here
WestNIC provides reliable web hosting services
Web hosting directory, find affordable web hosting
Fastwebhost offers cheap web hosting & reseller hosting services
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.
… full answer hidden, click for full answers
Premium members click below for full answer
How can I download a Web page and write it to a file?
A: Many Web sites use virtual hosting, which requires you send an HTTP Host header with your request.
… full answer hidden, click for full answers
Premium members click below for full answer
My Java Web client gets the wrong site!
A: 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.
… full answer hidden, click for full answers
Premium members click below for full answer
How can I set a code name identifier for my feed reader?
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();
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.
… full answer hidden, click for full answers
Premium members click below for full answer
How do I get the registered domain name from a URL?
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.
… full answer hidden, click for full answers
Premium members click below for full answer
How do I get a domain name from an IP address?
| Front-end FAQs | Back-end FAQs | Learn Java |
|---|---|---|
About us: site help, text ads and premium content FAQs.