• 大三学习进度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());
    }
    }
    }

    }

  • 相关阅读:
    C#综合揭秘——Entity Framework 并发处理详解
    Apache2.2+Tomcat7.0整合配置详解
    python操作excel
    NameError: name ‘time‘ is not defined
    ping命令最实用的
    github使用方法
    数字证书
    网络编程
    不辣的皮特
    msdn上的“索引器”(indexer)示例
  • 原文地址:https://www.cnblogs.com/hhw12345/p/14157405.html
Copyright © 2020-2023  润新知