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); } } }

      

  • 相关阅读:
    Android无线测试之—UiAutomator UiSelector API介绍之四
    Android无线测试之—UiAutomator UiSelector API介绍之三
    Android无线测试之—UiAutomator UiSelector API介绍之二
    网页抓取- 3
    VC 6.0 LNK2005 错误 处理
    抓取网页(3)之部分工程文件
    网页抓取 (2)
    网页抓取总结(一)
    nyoj-291 互素数个数 欧拉函数
    nyoj-257 郁闷的C小加(一) 前缀表达式变后缀
  • 原文地址:https://www.cnblogs.com/eRrsr/p/5948638.html
Copyright © 2011-2022 走看看