1 package hdfs; 2 3 import java.io.InputStream; 4 import java.net.URL; 5 6 import org.apache.hadoop.fs.FsUrlStreamHandlerFactory; 7 import org.apache.hadoop.io.IOUtils; 8 9 public class App1 { 10 /** 11 * 抛异常: unknown host: chaoren 12 * 原因:是因为本机没有解析主机名chaoren 13 */ 14 static final String PATH = "hdfs://chaoren:9000/hello"; 15 public static void main(String[] args) throws Exception { 16 URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory()); 17 18 final URL url = new URL(PATH); 19 final InputStream in = url.openStream(); 20 /** 21 * @param in 表示输入流 22 * @param out 表示输出流 23 * @param buffSize 表示缓冲大小 24 * @param close 表示在传输结束后是否关闭流 25 */ 26 IOUtils.copyBytes(in, System.out, 1024, true); 27 } 28 }
package hdfs;
import java.io.InputStream;import java.net.URL;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;import org.apache.hadoop.io.IOUtils;
public class App1 {/** * 抛异常: unknown host: chaoren * 原因:是因为本机没有解析主机名chaoren */static final String PATH = "hdfs://chaoren:9000/hello";public static void main(String[] args) throws Exception {URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());final URL url = new URL(PATH);final InputStream in = url.openStream();/** * @param in表示输入流 * @param out表示输出流 * @param buffSize表示缓冲大小 * @param close 表示在传输结束后是否关闭流 */IOUtils.copyBytes(in, System.out, 1024, true);}}