From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reading a text file over the Internet

Reading a text file over the Internet - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Reading a text file over the Internet

- Many Java applications have to communicate over the Internet making requests for content and processing the content after downloading it. I'll demonstrate one technique for doing this with core classes from the Java class library. I'm working in the "Internet" project and there's already a constant declared named "FLOWERS_FEED". This is the URL that points to a static XML file that's located on a remote server. I'll select that string and copy it to the clipboard, then I'll go to Google Chrome and I'll paste the string in and request the file, and I'll see that it's a simple XML file with a root element of "products", child elements of "product" and then more child elements within that. So now my job is to request that file and download it and display its contents for my application. I'll start in the "main" method and I'll create an instance of a class named URL. Notice that there's more than one URL class, be sure to choose the version from "java.net". I'll name it "url", all…

Contents