1.Hadoop-1.2.1 API 文档:http://hadoop.apache.org/docs/r1.2.1/api/

2.几个API:

  create(Path f) :Opens an FSDataOutputStream at the indicated Path.

  copyFromLocalFile(Path src, Path dst) :The src file is on the local disk.

  create(Path f) :Opens an FSDataOutputStream at the indicated Path.

  boolean exists(Path f) :Check if exists.

  get(URI uri, Configuration conf):Returns the FileSystem for this URI's scheme and authority.

  listStatus(Path f): List the statuses of the files/directories in the given path if the path is a directory.

  mkdirs(Path f) : Call mkdirs(Path, FsPermission) with default permission.

  rename(Path src, Path dst) :Renames Path src to Path dst.

3.代码实现:

import java.io.IOException;
import java.net.URI; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; public class testHDFS { static String hdfs = "hdfs://localhost:9000";
static Configuration conf = new Configuration(); public static void createFolder() throws IOException { FileSystem fs = FileSystem.get(URI.create(hdfs), conf);
Path path = new Path("/test");
fs.mkdirs(path);
fs.close();
} public static void createFile() throws IOException { FileSystem fs = FileSystem.get(URI.create(hdfs), conf);
Path path = new Path("/test/test3.txt");
FSDataOutputStream out = fs.create(path);
out.write("hello hadoop.".getBytes());
} public static void renameFile() throws IOException { FileSystem fs = FileSystem.get(URI.create(hdfs), conf);
Path path = new Path("/test/test1.txt");
Path newPath = new Path("/test/test2.txt");
System.out.println(fs.rename(path, newPath));
} public static void uploadFileToHDFS() throws IOException { FileSystem fs = FileSystem.get(URI.create(hdfs), conf);
Path src = new Path("/home/ares/test.txt");
Path dst = new Path("/test");
fs.copyFromLocalFile(src, dst);
} public static void listFile() throws IOException { FileSystem fs = FileSystem.get(URI.create(hdfs), conf);
Path path = new Path("/test");
FileStatus[] files = fs.listStatus(path);
for (FileStatus file : files) {
System.out.println(file.getPath().toString());
}
} public static void deleteFileOnHDFS() throws IOException {
FileSystem fs = FileSystem.get(URI.create(hdfs), conf);
Path path = new Path("/test/test2.txt");
boolean isExists = fs.exists(path);
if (isExists) {
fs.delete(path, isExists);
System.out.println("file is deleted.");
} else {
System.out.println("file is exist.");
}
} public static void main(String[] args) throws IOException {
// createFolder();
// createFile();
// renameFile();
// uploadFileToHDFS() ;
// listFile();
deleteFileOnHDFS();
}
}

HDFS API 学习:几个常用的API的更多相关文章

  1. ASP.NET MVC Web API 学习笔记---第一个Web API程序

    http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html GetListAll /api/Contact GetListBySex ...

  2. 【转载】ASP.NET MVC Web API 学习笔记---第一个Web API程序

    1. Web API简单说明 近来很多大型的平台都公开了Web API.比如百度地图 Web API,做过地图相关的人都熟悉.公开服务这种方式可以使它易于与各种各样的设备和客户端平台集成功能,以及通过 ...

  3. ASP.NET MVC Web API 学习笔记---第一个Web API程序【转】

    http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html 1. Web API简单说明 近来很多大型的平台都公开了Web API. ...

  4. ASP.NET MVC Web API 学习笔记---第一个Web API程序---近来很多大型的平台都公开了Web API

    1. Web API简单说明 近来很多大型的平台都公开了Web API.比如百度地图 Web API,做过地图相关的人都熟悉.公开服务这种方式可以使它易于与各种各样的设备和客户端平台集成功能,以及通过 ...

  5. Java基础学习笔记(五) - 常用的API

    API介绍 概念:API 即应用编程程序接口.Java API是JDK中提供给我们使用的类说明文档,这些类将底层的代码实现封装.无需关心这些类是如何实现,只需要学习如何使用. 使用:通过API找到需要 ...

  6. JDBC主要API学习总结

    JDBC主要API学习 一.JDBC主要API简介 JDBC API 是一系列的接口,它使得应用程序能够进行数据库联接,执行SQL语句,并且得到返回结果. 二.Driver 接口 Java.sql.D ...

  7. Servlet 常用API学习(三)

    Servlet常用API学习 (三) 一.HTTPServletRequest简介 Servlet API 中定义的 ServletRequest 接口类用于封装请求消息. HttpServletRe ...

  8. Servlet 常用API学习(二)

    Servlet常用API学习 一.HTTP简介 WEB浏览器与WEB服务器之间的一问一答的交互过程必须遵循一定的规则,这个规则就是HTTP协议. HTTP是 hypertext transfer pr ...

  9. Servlet 常用API学习(一)

    Servlet常用API学习 一.Servlet体系结构(图片来自百度图片) 二.ServletConfig接口 Servlet在有些情况下可能需要访问Servlet容器或借助Servlet容器访问外 ...

随机推荐

  1. C#的23种设计模式概括

    创建型:         1. 单件模式(Singleton Pattern)         2. 抽象工厂(Abstract Factory)         3. 建造者模式(Builder) ...

  2. bootstrap table表格属性、列属性、事件、方法

    留存一份,原文地址http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ 表格参数 表格的参数定义在 jQuery.fn.bootst ...

  3. [bzoj3004] [SDOi2012]吊灯

    Description Alice家里有一盏很大的吊灯.所谓吊灯,就是由很多个灯泡组成.只有一个灯泡是挂在天花板上的,剩下的灯泡都是挂在其他的灯泡上的.也就是说,整个吊灯实际上类似于[b]一棵树[/b ...

  4. innodb log file与binlog的区别在哪里?

    Q: innodb log file与binlog的区别在哪里?有人说1.mysql的innodb引擎实际上是包装了inno base存储引擎.而innodb log file是由 inno base ...

  5. 解析json方式之net.sf.json

    前面转载了json解析的技术:fastjson,今天说下另外一种技术. 下载地址 本次使用版本:http://sourceforge.net/projects/json-lib/files/json- ...

  6. libusb 示例

    #include <usb.h> #include <stdio.h> #define VERSION "0.1.0" #define VENDOR_ID ...

  7. jquery.cookie.js 的使用指南

    转自:http://www.cnblogs.com/yjzhu/p/4359420.html 介绍: jquery.cookie.js 是一款轻量级的 cookie 插件,可以读取,写入和删除 coo ...

  8. PostgreSQL(Linux)安装、启动、停止、重启

    If we don't already have PostgreSQL installed, we must install it. $ sudo apt-get install postgresql ...

  9. centos yum 安装 mysql

      centos7下使用yum安装mysql 时间:2015-03-07 21:26:20      阅读:87445      评论:0      收藏:1      [点我收藏+] 标签: Cen ...

  10. c语言几个字符串处理函数的简单实现

    直接贴代码: char* strcpy(char *a,char*b){//把字符串b全部拷贝到a中 assert(a != nullptr&&b != nullptr); char ...