February 2019
Beginner to intermediate
544 pages
14h 36m
English
We will talk about two approaches to reading a file and will discuss when to use what. In the first approach, we can use the URL class, which is part of the java.net package and can be used to read files stored on HDFS. The URL calls setURLStreamHandlerFactory(), which requires an instance of FsUrlStreamHandlerFactory(). This initialization is a part of a static block that is executed before any instance creation. This method is in a static block because it can only be called once per JVM and hence, if any third-party program sets URLStreamHandlerFactory, we won't be able to use it for reading files from HDFS:
static { URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory()); }
Once the URL has been initialized, it opens ...
Read now
Unlock full access