BigPig 2013-05-20
1. 配置Hadoop
将下载的Hadoop压缩文件解压缩,找到conf目录,打开core-site.xml,修改代码如下所示:
package cn.com.fri; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URISyntaxException; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileContext; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.security.AccessControlException; public class Test { public static void main(String[] args) throws AccessControlException, FileNotFoundException, IOException, URISyntaxException { FileContext fc = FileContext .getFileContext();//如果运行在hadoop location中,不需要配置URI,否则需要给一个URI FSDataInputStream fsInput = fc.open(new Path( "/tmp/hadoop-alex/persons.rtf")); IOUtils.copyBytes(fsInput, System.out, 4090, false); fsInput.seek(0); IOUtils.copyBytes(fsInput, System.out, 4090, false); } }
然后右键->Run As->Run on hadoop,此时会让你选择一个location,就选中我们刚才新建的location即可。