zoukankan      html  css  js  c++  java
  • 大三学习进度3

    //java对hadoop操作示例

    import java.io.IOException;
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FSDataOutputStream;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;

    public class WriteFile {
    public static void main(String[] args) throws IOException {
    FileSystem fs = FileSystem.get(new URI("hdfs://linux1:9000"),
    new Configuration(),"root");
    Path path = new Path("/user/hadoop/data/write.txt");
    FSDataOutputStream out = fs.create(path);
    out.writeUTF("da jia hao,cai shi zhen de hao!");
    fs.close();
    }
    }

    import java.io.IOException;
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileStatus;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;

    public class GetAllChildFile {
    static Configuration conf = new Configuration();

    public static void main(String[] args)throws IOException {
    FileSystem fs = FileSystem.get("hdfs://linux1:9000"),
    new Configuration(),"root");
    Path path = new Path("/user/hadoop");
    getFile(path,fs);
    //fs.close();
    }
    public static void getFile(Path path,FileSystem fs) throws IOException {
    FileStatus[] fileStatus = fs.listStatus(path);
    for(int i=0;i<fileStatus.length;i++){
    if(fileStatus[i].isDir()){
    Path p = new Path(fileStatus[i].getPath().toString());
    getFile(p,fs);
    }else{
    System.out.println(fileStatus[i].getPath().toString());
    }
    }
    }

    }

  • 相关阅读:
    Windows Server 2012 R2 或 2016 无法安装 .Net 3.5.1
    织梦DeDeCms会员登录或退出跳转到首页的修改方法
    use ngCordova in ionic
    Angular2 Todo App
    use traceur in ES6
    Angular2 Use styles in Component
    Angular2 use ng-xx (ng-if)
    Angular2 Router
    Angular2 Http
    1 TypeScript SetUp for Webstorm
  • 原文地址:https://www.cnblogs.com/hhw12345/p/14157405.html
Copyright © 2011-2022 走看看