zoukankan      html  css  js  c++  java
  • Hadoop.2.x_简单的测试文件读取与上传

    代码如下, 后备参考:

    package com.bigdata.hadoop.hdfs;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FSDataInputStream;
    import org.apache.hadoop.fs.FSDataOutputStream;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IOUtils;
    import org.junit.Test;
    
    public class HdfsTest {
    	
    	public static FileSystem getFileSystem() throws IOException{
    Configuration configuration = new Configuration(); //Some configurations used to replace the configuration of resource files //configuration.set("fs.defaultFS", "hdfs://linux-66-64.liuwl.com:8020"); //... return FileSystem.get(configuration); } @Test public static void read() throws IOException{ String fileName = "/user/liuwl/tmp/core-site.xml"; FileSystem fileSystem = getFileSystem(); Path path = new Path(fileName); FSDataInputStream instream = fileSystem.open(path); try{ IOUtils.copyBytes(instream, System.out, 4896,false); }catch(Exception e){ e.getStackTrace(); }finally{ IOUtils.closeStream(instream); } } @Test public void write() throws IOException{ String fileName = "/user/liuwl/tmp/input/wc.input"; FileSystem fileSystem = getFileSystem(); Path writePath = new Path(fileName); FSDataOutputStream outStream = fileSystem.create(writePath); FileInputStream inStream = new FileInputStream(new File("/home/liuwl/opt/data/wc.input")); try{ IOUtils.copyBytes(inStream, outStream, 4896,false); }catch(Exception e){ e.getStackTrace(); }finally{ IOUtils.closeStream(inStream); IOUtils.closeStream(outStream); } } }

      

  • 相关阅读:
    使用策略模式减少if else
    php 向二维数组中追加元素
    svn update 产生Node remains in conflict的问题
    php对ip地址的处理
    php 对比两个数组中的值是否相等
    jquery 通过attr获取属性只有一个值的解决
    php 一维数组去重
    调整ceph的pg数(pg_num, pgp_num)
    linux-Centos 7下bond与vlan技术的结合[推荐]
    centos 配置vlan
  • 原文地址:https://www.cnblogs.com/eRrsr/p/5948638.html
Copyright © 2011-2022 走看看