1. Source Code
Import org.apache.hadoop.fs.fsurlstreamhandlerfactory;import org.apache.hadoop.io.ioutils;import java.io.inputstream;import java.net.url;/** * example 3.1 */public class URLCat { static { Url.seturlstreamhandlerfactory (New fsurlstreamhandlerfactory ()); } public static void main (String[] args) throws Exception { InputStream in = null; try { in = new url (Args[0]). OpenStream (); ioutils.copybytes (In, system.out, 4096, false); } finally {&nbsP; ioutils.closestream (in); } }}
package cn.kissoft.hadoop.week04;import org.apache.hadoop.conf.configuration;import Org.apache.hadoop.fs.filesystem;import org.apache.hadoop.fs.path;import org.apache.hadoop.io.ioutils ;import java.io.inputstream;import java.net.uri;/** * example 3.2 */public Class homework1 { public static void main (String[] args) throws Exception { String uri = args[0]; configuration conf = new Configuration (); filesystem fs = filesystem.get ( Uri.create (URI), conf); inputstream in = null; try { in = fs.open (New path (URI)); Ioutils.copybytes (In, system.out, 4096, false); } finally { Ioutils.closestream (in); } }}
2. How to run the. Class
Note: In this example, the Urlcat class is in the default package, and if there is a package, the class name should be preceded by a packet.
3. How the. Jar Runs