Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2293518
  • 博文数量: 276
  • 博客积分: 5998
  • 博客等级: 大校
  • 技术积分: 5175
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 14:43
文章分类

全部博文(276)

文章存档

2014年(25)

2013年(11)

2012年(69)

2011年(167)

2010年(4)

分类: HADOOP

2014-03-24 16:25:08


如果用eclipse 连接hadoop测试 一定要把core-site.xml  hdfs-site.xml 放到和包test同目录下 不然会报错程序会报File not found错误,并且加载相对应版本的的hadoop-core-xx.jar包

点击(此处)折叠或打开

  1. package test;
  2. import java.io.*;
  3. import java.util.*;
  4. import java.net.*;
  5. import org.apache.hadoop.fs.*;
  6. import org.apache.hadoop.conf.*;
  7. import org.apache.hadoop.io.*;
  8. import org.apache.hadoop.mapred.*;
  9. import org.apache.hadoop.util.*;
  10.  
  11. public class Cat{
  12.         public static void main (String [] args) throws Exception{
  13.                 try{
  14.                         Path pt=new Path("hdfs://10.14.2.201:9000/user/hadoop/words.txt");
  15.                         //Path pt=new Path("hdfs://npvm11.np.wc1.yellowpages.com:9000/user/john/abc.txt");
  16.                         FileSystem fs = FileSystem.get(new Configuration());
  17.                         BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt)));
  18.                         String line;
  19.                         line=br.readLine();
  20.                         long sum = 0L;
  21.                         while (line != null){
  22.                                 sum ++;
  23.                                 System.out.println(line+"sum: "+sum);
  24.                                 line=br.readLine();
  25.                         }
  26.                 }catch(Exception e){
  27.                     e.printStackTrace();
  28.                 }
  29.         }
  30. }

阅读(3443) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~