zoukankan      html  css  js  c++  java
  • hadoop第一个例子

    Java.io.URL

    1、编写java程序

    package com.company;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
    import org.apache.hadoop.io.IOUtils;
    
    public class Main {
        static {
            URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
        }
    
        public static void main(String[] args) throws MalformedURLException,IOException {
            InputStream in=null;
            try{
                in = new URL(args[0]).openStream();
                IOUtils.copyBytes(in,System.out,4096,false);
            }finally {
                IOUtils.closeStream(in);
            }
        }
    }

    2、打包为javaWrkspace.jar

    3、simon@simon-Lenovo-G400:~/software/hadoop$

    bin/hadoop jar /home/simon/javaWrkspace/out/artifacts/javaWrkspace_jar/javaWrkspace.jar  hdfs://localhost:9000/test/hello

    org.apache.hadoop.fs.FileSystem

    1、

    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URI;
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IOUtils;
    public class hdfsclient {
        public static void main(String[] args) throws IOException{
            String uri="hdfs://localhost:9000/test/hello";
            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、打包为javaWrkspace.jar

    3、simon@simon-Lenovo-G400:~/software/hadoop$

    bin/hadoop jar /home/simon/javaWrkspace/out/artifacts/javaWrkspace_jar2/javaWrkspace.jar  hdfsclient

  • 相关阅读:
    内网穿透教程
    深入浅出 TCP/IP 协议栈
    STM32CUBEMX配置RTC闹钟
    RT-Thread STM32 系列 BSP 制作教程
    RT-Thread 在stm小内存系列产品的nano+msh完整移植教程
    C语言字符串与数字相互转换
    SD卡 TF卡 接口引脚定义
    定位数据格式
    安信可ESP-12F连接阿里云教程
    电脑使用网络调试助手连接阿里云步骤
  • 原文地址:https://www.cnblogs.com/ggzhangxiaochao/p/9248796.html
Copyright © 2011-2022 走看看