hadoop实例之HELLOWORLD

来源:互联网 发布:buffer在c语言 编辑:程序博客网 时间:2024/05/21 17:57

新建一个Map/Reduce工程文件:HelloWorld.java


import java.io.OutputStream;

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

public class HelloWorld {
    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration();
        FileSystem fs = FileSystem.get(configuration);
        OutputStream out = fs.create(new Path("./input/555.txt"));
        String str = "Hello World 555";
        out.write(str.getBytes());
        out.flush();
        out.close();
    }

}


在src的目录下创建一个文件夹input及输出文件555.txt,运行java程序,打开555.txt可以看到Hello World 555


原创粉丝点击