hadoop学习笔记(一)

Hadoop之FileSystem文件的操作

//读数据
Hadoop中的IOUtils类的两个静态方法:
1)IOUtils.copyBytes(),其中in表示拷贝源,System.out表示拷贝目的地(也就是要拷贝到标准输出中去),4096表示用来拷贝的buffer大小,false表明拷贝完成后我们并不关闭拷贝源可拷贝目的地(因为System.out并不需要关闭,in可以在finally语句中被关闭)。
2)IOUtils.closeStream(),用来关闭一个流

public class FileSystemDoubleCat {
       public static void main(String[] args) throws Exception {
          String uri = args[0];
          Configuration conf = new Configuration();
          FileSystem fs = FileSystem.get(URI.create(uri), conf);
          FSDataInputStream in = null;
     try {
           in = fs.open(new Path(uri));
           IOUtils.copyBytes(in, System.out, 4096, false);
           in.seek(0); // go back to the start of the file
           IOUtils.copyBytes(in, System.out, 4096, false);
     } finally {
           IOUtils.closeStream(in);
     }
   }
 }

//写数据

public class FileCopyWithProgress {
      public static void main(String[] args) throws Exception {
          String localSrc = args[0];
          String dst = args[1];
          InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
          Configuration conf = new Configuration();
          FileSystem fs = FileSystem.get(URI.create(dst), conf);
          OutputStream out = fs.create(new Path(dst), new Progressable() {
              public void progress() {
                 System.out.print(".");
             }
         });
         IOUtils.copyBytes(in, out, 4096, true);
     }
 }

//getFileStatus()方法提供了获取某个给定文件或目录的FileStatus对象的途径(略,见http://www.tuicool.com/articles/NvQf6b

//创建

fs.mkdirs(newPath(DIR_PATH));

//删除

fs.delete(newPath(FILE_PATH), true);

hadoop yarn web service
假设你有一个application_1388830974669_1540349作业,并且运行完了。可以通过下面的命令得到这个作业的一些信息:
$ curl –compressed -H”Accept: application/json”-X \
GET “http://master:8088/ws/v1/cluster/apps/application_1388830974669_1540349“会以json格式返回数据信息

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值