zoukankan      html  css  js  c++  java
  • hadoop文件读取并输出

    package a;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.*;


    public class a2 extends FSDataInputStream{

    /**
    * @param args
    */
    public a2(InputStream in){
    super(in);
    }
    public static String readline(Configuration conf,String remoteFilePath){
    try (FileSystem fs = FileSystem.get(conf)) {
    Path remotePath = new Path(remoteFilePath);
    FSDataInputStream in = fs.open(remotePath);
    BufferedReader d = new BufferedReader(new InputStreamReader(in));
    String line = null;
    if ((line = d.readLine()) != null) {
    d.close();
    in.close();
    return line;
    }
    return null;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return null;
    }

    }

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Configuration conf=new Configuration();
    conf.set("fs.default.name","hdfs://localhost:9000");
    String remoteFilePath="/test";

    System.out.println("连接到+remoteFilePath);
    System.out.println(a2.readline(conf, remoteFilePath));
    System.out.println(" 输出完毕");
    }

    }

  • 相关阅读:
    Flask【第11篇】:整合Flask中的目录结构
    GIMP简介
    java 二进制数字符串转换工具类
    Linux nohup 命令
    Linux & 命令
    linux 下检查java jar包 程序是否正常 shell
    linux 下启动java jar包 shell
    linux 下停止java jar包 shell
    shell 中的特殊变量
    maven settings 配置文件
  • 原文地址:https://www.cnblogs.com/liuleliu/p/13875643.html
Copyright © 2011-2022 走看看