通过API操作HDFS

今天的主要内容

HDFS获取文件系统

HDFS文件上传

HDFS文件下载

HDFS目录创建

HDFS文件夹删除

HDFS文件名更改

HDFS文件详情查看

定位文件读取

FileSystem类的学习

1. HDFS获取文件系统

//获取文件系统

@Test

public void initHDFS() throws Exception{

//1. 获取文件系统

Configuration configuration = new Configuration();

FileSystem fileSystem = FileSystem.get(configuration);

//2. 打印文件系统到控制台

System.out.println(fileSystem.toString());

}

2. HDFS文件上传(测试参数优先级)

@Test

public void putFileToHdfs() throws Exception{

Configuration conf = new Configuration();

conf.set("dfs.replication", "2"); //代码优先级是最高的

conf.set("fs.defaultFS", "hdfs://10.9.190.111:9000");

FileSystem fileSystem = FileSystem.get(conf);

//上传文件

fileSystem.copyFromLocalFile(new Path("hdfs.txt"), new Path("/user/anna/hdfs/test.txt"));

//关闭资源

fileSystem.close();

}

参数优先级:(1)客户端代码中设置的值 >(2)classpath 下的用户自定义配置文件 > (3)然后是服务器的默认配置

3. HDFS文件下载

public void copyToLocalFile(boolean delSrc,Path src,Path dst,boolean useRawLocalFileSystem)

throws IOException

delSrc - whether to delete the src

src - path

dst - path

useRawLocalFileSystem - whether to use RawLocalFileSystem as local file system or not.

@Test

public void testCopyToLocalFile() throws Exception{

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://10.9.190.111:9000");

FileSystem fileSystem = FileSystem.get(conf);

///下载文件

fileSystem.copyToLocalFile(false,new Path("/user/anna/hdfs/test.txt"), new Path("test.txt"),true);

//关闭资源

fileSystem.close();

}

4. HDFS目录创建

@Test

public void testMakedir() throws Exception{

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://10.9.190.111:9000");

FileSystem fileSystem = FileSystem.get(conf);

//目录创建

fileSystem.mkdirs(new Path("/user/anna/test/hahaha"));

//关闭资源

fileSystem.close();

}

5. HDFS文件夹删除

@Test

public void testDelete() throws Exception{

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://10.9.190.111:9000");

FileSystem fileSystem = FileSystem.get(conf);

//文件夹删除

fileSystem.delete(new Path("/user/anna/test/hahaha"),true); //true表示递归删除

//关闭资源

fileSystem.close();

}

6. HDFS文件名更改

@Test

public void testRename() throws Exception{

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://10.9.190.111:9000");

FileSystem fileSystem = FileSystem.get(conf);

//文件名称更改

fileSystem.rename(new Path("/user/anna/test/copy.txt"), new Path("/user/anna/test/copyRename.txt"));

//关闭资源

fileSystem.close();

}

7. HDFS文件详情查看

几种实现方法

1. public abstract FileStatus[] listStatus(Path f) throws FileNotFoundException,IOException

* 返回FileStatus型数组

2. public FileStatus[] listStatus(Path f,PathFilter filter) throws FileNotFoundException,IOException

3. public FileStatus[] listStatus(Path[] files,PathFilter filter) throws FileNotFoundException,IOException

* 此时注意PathFilter是一个接口,里面只有一个方法:accept,本质是对文件进行筛选

* Enumerate all files found in the list of directories passed in, calling listStatus(path, filter) on each one.

注意:以上方法返回的文件按照字母表顺序排列

代码:FileStatus[] listStatus(Path f)

//FileStatus[] listStatus(Path f)的使用

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//listStatus获取/test目录下信息

FileStatus[] fileStatuses = fileSystem.listStatus(new Path("/test"));

//遍历输出文件夹下文件

for(FileStatus fileStatus :fileStatuses) {

System.out.println(fileStatus.getPath() + " " + new Date(fileStatus.getAccessTime()) + " " +

fileStatus.getBlockSize() + " " + fileStatus.getPermission());

}

}catch(Exception e) {

e.printStackTrace();

}

/*

在JDK1.8中输出结果为:

----------------------------------------------------------------------------

hdfs://10.9.190.90:9000/test/hadoop-2.7.3.tar.gz 2012-07-26 134217728 rw-r--r--

hdfs://10.9.190.90:9000/test/hello.txt 2012-07-26 134217728 rw-r--r--

hdfs://10.9.190.90:9000/test/test2 1970-01-01 0 rwxr-xr-x

----------------------------------------------------------------------------

*/

代码:FileStatus[] listStatus(Path f,PathFilter filter)

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//列出目录下后缀为.md的文件相关信息

FileStatus[] statuses = fileSystem.listStatus(new Path("/test/test2"), new PathFilter() {

@Override

public boolean accept(Path path) {

// TODO Auto-generated method stub

String string = path.toString();

if(string.endsWith(".md"))

return true;

else

return false;

}

});

//列出文件信息

for(FileStatus status : statuses) {

System.out.println("Path : " + status.getPath() + " Permisson : " + status.getPermission() +

" Replication : " + status.getReplication());

}

}catch(Exception e) {

e.printStackTrace();

}

7. 定位文件读取

8. FileSystem类的学习

FileSystem的学习

今天的主要内容

对照官方文档进行FileSystem类的学习

FileSystem中的方法

* boolean exists(Path p)

* boolean isDirectory(Path p)

* boolean isFile(Path p)

* FileStatus getFileStatus(Path p)

* Path getHomeDirectory()

* FileStatus[] listStatus(Path path, PathFilter filter)

FileStatus[] listStatus(Path path)

FileStatus[] listStatus(Path[] paths, PathFilter filter)

FileStatus[] listStatus(Path[] paths)

* RemoteIterator[LocatedFileStatus] listLocatedStatus(Path path, PathFilter filter)

RemoteIterator[LocatedFileStatus] listLocatedStatus(Path path)

RemoteIterator[LocatedFileStatus] listFiles(Path path, boolean recursive)

* BlockLocation[] getFileBlockLocations(FileStatus f, int s, int l)

BlockLocation[] getFileBlockLocations(Path P, int S, int L)

* long getDefaultBlockSize()

long getDefaultBlockSize(Path p)

long getBlockSize(Path p)

* boolean mkdirs(Path p, FsPermission permission)

* FSDataOutputStream create(Path, ...)

FSDataOutputStream append(Path p, int bufferSize, Progressable progress)

FSDataInputStream open(Path f, int bufferSize)

* boolean delete(Path p, boolean recursive)

* boolean rename(Path src, Path d)

* void concat(Path p, Path sources[])

* boolean truncate(Path p, long newLength)

* interface RemoteIterator

boolean hasNext()

E next()

* interface StreamCapabilities

boolean hasCapability(capability)

准备工作

start-dfs.sh启动hadoop集群

eclipse进行hdfs文件系统的访问

导入相应的jar包

创建与hdfs的连接并获取FileSystem文件对象

第一种方式

* public static FileSystem get(Configuration conf) throws IOException

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000"); //namenode上的IP地址 端口为:9000

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

第二种方式

* public static FileSystem get(URI uri,Configuration conf,String user)

throws IOException,

InterruptedException

URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());

FileSystem fileSystem = FileSystem.get(new URI("hdfs://10.9.190.90:9000"),new Configuration(),"root");

//此时工作目录会相应更改为/user/root

两种方式比较

第二种方式可能会抛出InterruptedException异常,因为

the static FileSystem get(URI uri, Configuration conf,String user) method MAY return a pre-existing instance of a filesystem client class—a class that may also be in use in other threads. The implementations of FileSystem shipped with Apache Hadoop do not make any attempt to synchronize access to the working directory field.(此时get方法可能会返回一个已经存在FileSystem对象,也就是存在线程异步问题,所以我们尽量用前一种方式来完成FileSystem对象的创建)

org.apache.hadoop.fs.FileSystem简介

The abstract FileSystem class is the original class to access Hadoop filesystems; non-abstract subclasses exist for all Hadoop-supported filesystems.(抽象基类FileSystem定义了对hadoop文件系统的操作)

All operations that take a Path to this interface MUST support relative paths. In such a case, they must be resolved relative to the working directory defined by setWorkingDirectory().(setWorkingDirectory()方法默认工作目录)

FileSystem中的getWorkingDirector()返回当前系统的工作目录

代码

//获得与hdfs文件系统的连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://10.9.190.90:9000");

//获取文件系统对象

FileSystem fileSystem = FileSystem.get(conf);

//获取当前工作目录

System.out.println("=========获取当前工作目录=============");

System.out.println(fileSystem.getWorkingDirectory());

//设置新的工作目录

//System.out.println("=========设置新的工作目录=============");

fileSystem.setWorkingDirectory(new Path("hdfs://10.9.190.90:9000/user/anna")); //Path在hdfs中的作用和File作用类似,代表路径

结果

=========获取当前工作目录=============

hdfs://10.9.190.90:9000/user/root

=========获取设置后工作目录=============

hdfs://10.9.190.90:9000/user/anna

FileSystem方法——判断功能

预备知识

import org.apache.hadoop.fs.Path;类似于java.io.File代表hdfs的文件路径

方法

public boolean exists(Path f) throws IOException

判断文件是否存在

public boolean isDirectory(Path f) throws IOException

判断是否为目录

public boolean isFile(Path f) throws IOException

判断是否为文件

练习

try {

//获得与hdfs文件系统的连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://10.9.190.90:9000");

//获取连接对象

FileSystem fileSystem = FileSystem.get(conf);

//判断文件是否存在

System.out.println(fileSystem.exists(new Path("/test"))); //true

//判断是否为目录

System.out.println(fileSystem.isDirectory(new Path("/test"))); //true

//判断是否为文件

System.out.println(fileSystem.isFile(new Path("/test"))); //false

}catch(Exception e) {

e.printStackTrace();

}

FileSystem方法——获取功能—文件信息获取

方法

public abstract FileStatus getFileStatus(Path f) throws IOException

Return a file status object that represents the path.

返回的是FileStatus对象类型

public Path getHomeDirectory()

Return the current user's home directory in this FileSystem. The default implementation returns "/user/$USER/".

返回当前用户的home目录

练习

try {

//获得与hdfs文件系统的连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://10.9.190.90:9000");

//获取连接对象

FileSystem fileSystem = FileSystem.get(conf);

//获取当前用户的home目录

System.out.println("========当前用户的home目录============");

Path path = fileSystem.getHomeDirectory();

System.out.println(path);

//获取文件状态对象

System.out.println("============文件信息===============");

FileStatus status = fileSystem.getFileStatus(new Path("/eclipse"));

System.out.println("Path : " + status.getPath());

System.out.println("isFile ? " + status.isFile());

System.out.println("Block size : " + status.getBlockSize());

System.out.println("Perssions : " + status.getPermission());

System.out.println("Replication : " + status.getReplication());

System.out.println("isSymlink : " + status.isSymlink());

}catch(Exception e) {

e.printStackTrace();

}

/*

在JDK1.8中输出结果为:

* ------------------------------------------------

* ========当前用户的home目录============

hdfs://10.9.190.90:9000/user/anna

============文件信息===============

Path : hdfs://10.9.190.90:9000/eclipse

isFile ? true

Block size : 134217728

Perssions : rw-r--r--

Replication : 3

isSymlink : false

------------------------------------------------

*/

FileStatus中常用方法

public Path getPath()

public boolean isFile()

public boolean isSymlink()

public long getBlockSize()

public short getReplication()

public FsPermission getPermission()

FileSystem方法——获取功能——文件夹遍历1

方法

public abstract FileStatus[] listStatus(Path f) throws FileNotFoundException,IOException

返回FileStatus型数组

public FileStatus[] listStatus(Path f,PathFilter filter)

throws FileNotFoundException,IOException

public FileStatus[] listStatus(Path[] files,PathFilter filter)

throws FileNotFoundException,IOException

此时注意PathFilter是一个接口,里面只有一个方法:accept,本质是对文件进行筛选

Enumerate all files found in the list of directories passed in, calling listStatus(path, filter) on each one.

注意:以上方法返回的文件按照字母表顺序排列

练习1——FileStatus[] listStatus(Path f)的使用

//FileStatus[] listStatus(Path f)的使用

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//listStatus获取/test目录下信息

FileStatus[] fileStatuses = fileSystem.listStatus(new Path("/test"));

//遍历输出文件夹下文件

for(FileStatus fileStatus :fileStatuses) {

System.out.println(fileStatus.getPath() + " " + new Date(fileStatus.getAccessTime()) + " " +

fileStatus.getBlockSize() + " " + fileStatus.getPermission());

}

}catch(Exception e) {

e.printStackTrace();

}

/*

在JDK1.8中输出结果为:

----------------------------------------------------------------------------

hdfs://10.9.190.90:9000/test/hadoop-2.7.3.tar.gz 2012-07-26 134217728 rw-r--r--

hdfs://10.9.190.90:9000/test/hello.txt 2012-07-26 134217728 rw-r--r--

hdfs://10.9.190.90:9000/test/test2 1970-01-01 0 rwxr-xr-x

----------------------------------------------------------------------------

*/

练习2——FileStatus[] listStatus(Path f,PathFilter filter)的使用

需求:列出/test/test2目录下以.md结尾的问价信息

代码:

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//列出目录下后缀为.md的文件相关信息

FileStatus[] statuses = fileSystem.listStatus(new Path("/test/test2"), new PathFilter() {

@Override

public boolean accept(Path path) {

// TODO Auto-generated method stub

String string = path.toString();

if(string.endsWith(".md"))

return true;

else

return false;

}

});

//列出文件信息

for(FileStatus status : statuses) {

System.out.println("Path : " + status.getPath() + " Permisson : " + status.getPermission() +

" Replication : " + status.getReplication());

}

}catch(Exception e) {

e.printStackTrace();

}

注意问题

By the time the listStatus() operation returns to the caller, there is no guarantee that the information contained in the response is current. The details MAY be out of date, including the contents of any directory, the attributes of any files, and the existence of the path supplied.(listStatus()方法线程不安全)

FileSystem方法——获取功能——文件夹遍历2

方法

public org.apache.hadoop.fs.RemoteIterator listLocatedStatus(Path f)

throws FileNotFoundException, IOException

protected org.apache.hadoop.fs.RemoteIterator listLocatedStatus(Path f,PathFilter filter)

throws FileNotFoundException, IOException

注意:此方法是protected的,protected权限是:本类,同一包下(子类或无关类),不同包下子类

注意:LocatedFileStatus是FileStatus的子类

使用

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//列出目录下后缀为.md的文件相关信息

RemoteIterator iterator = fileSystem.listLocatedStatus(new Path("/test/test2"));

while(iterator.hasNext()) {

LocatedFileStatus status = iterator.next();

System.out.println("Path : " + status.getPath() + " Permisson : " + status.getPermission() +

" Replication : " + status.getReplication());

}

}catch(Exception e) {

e.printStackTrace();

}

/*

* 在JDK1.8中输出结果为:

* ---------------------------------------------------------------------------------------------

* Path : hdfs://10.9.190.90:9000/test/test2/Map.md Permisson : rw-r--r-- Replication : 3

Path : hdfs://10.9.190.90:9000/test/test2/biji.md Permisson : rw-r--r-- Replication : 3

Path : hdfs://10.9.190.90:9000/test/test2/haha.txt Permisson : rw-r--r-- Replication : 3

---------------------------------------------------------------------------------------------

* */

与listStatus(Path p)不同的是

listStatus返回的是FileStatus[]数组类型,遍历时可通过数组for-each进行遍历

listLocatedStatus(Path p)返回的是LocatedFileStatus类型的RemoteIterator集合,通过迭代器进行遍历输出

但是要注意的是listLocatedStatus()方法本质上内部还是listStatus(Path p)实现的

FileSystem方法——获取功能——文件夹遍历3

方法

public org.apache.hadoop.fs.RemoteIterator listFiles(Path f,boolean recursive)

throws FileNotFoundException,IOException

递归遍历出文件夹内容以及子文件夹中内容

使用

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//列出目录下后缀为.md的文件相关信息

RemoteIterator iterator = fileSystem.listFiles(new Path("/test"),true);

while(iterator.hasNext()) {

LocatedFileStatus status = iterator.next();

System.out.println("Path : " + status.getPath() + " Permisson : " + status.getPermission() +

" Replication : " + status.getReplication());

}

}catch(Exception e) {

e.printStackTrace();

}

/*

* 在JDK1.8中输出结果为:

* ---------------------------------------------------------------------------------------------------

* Path : hdfs://10.9.190.90:9000/test/hadoop-2.7.3.tar.gz Permisson : rw-r--r-- Replication : 3

Path : hdfs://10.9.190.90:9000/test/hello.txt Permisson : rw-r--r-- Replication : 3

Path : hdfs://10.9.190.90:9000/test/test2/Map.md Permisson : rw-r--r-- Replication : 3

Path : hdfs://10.9.190.90:9000/test/test2/biji.md Permisson : rw-r--r-- Replication : 3

Path : hdfs://10.9.190.90:9000/test/test2/haha.txt Permisson : rw-r--r-- Replication : 3

---------------------------------------------------------------------------------------------------

* */

FileSystem方法——获取功能——获取文件block的位置

方法

public BlockLocation[] getFileBlockLocations(Path p,long start,long len) throws IOException

public BlockLocation[] getFileBlockLocations(FileStatus file,long start,long len) throws IOException

使用

//查看/test/hadoop的block存放位置

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

FileStatus status = fileSystem.getFileStatus(new Path("/test/hadoop"));

BlockLocation[] locations = fileSystem.getFileBlockLocations(status, 0,status.getLen());

for(BlockLocation location : locations) {

System.out.println("host : " + location.getHosts() + " name : " + location.getNames() + " length : " + location.getLength());

}

}catch(Exception e) {

e.printStackTrace();

}

/*

在JDK1.8中输出结果为:

------------------------------------------------------------------------------

host : [Ljava.lang.String;@18ece7f4 name : [Ljava.lang.String;@3cce57c7 length : 134217728

host : [Ljava.lang.String;@1cf56a1c name : [Ljava.lang.String;@33f676f6 length : 79874467

------------------------------------------------------------------------------

*/

FileSystem方法——获取功能——获取到某文件的输出流

方法

public FSDataOutputStream create(Path f) throws IOException

public FSDataOutputStream create(Path f,boolean overwrite)

throws IOException

overwrite - if a file with this name already exists, then if true, the file will be overwritten, and if false an exception will be thrown.

public FSDataOutputStream create(Path f,

Progressable progress)

throws IOException

Create an FSDataOutputStream at the indicated Path with write-progress reporting. Files are overwritten by default.

public FSDataOutputStream create(Path f,boolean overwrite,int bufferSize)

throws IOException

public FSDataOutputStream create(Path f,boolean overwrite,int bufferSize, Progressable progress)throws IOException

FSDataOutputStream append(Path p, int bufferSize, Progressable progress)

使用——将本地E:/hzy.jpg上传到hdfs的/1.jpg

public static void main(String[] args) {

BufferedInputStream in = null;

FSDataOutputStream out = null;

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//获取本地文件输入流

File file = new File("E:/hzy.jpg");

in = new BufferedInputStream(new FileInputStream(file));

final long fileSize = file.length();

//获取到/test/hello.txt的输出流

out = fileSystem.create(new Path("/1.jpg"),new Progressable() {

long fileCount = 0;

@Override

public void progress() {

// TODO Auto-generated method stub

fileCount++;

System.out.println("总进度:" + (fileCount/fileSize)*100 + " %");

}

});

//拷贝

int len = 0;

while((len = in.read()) != -1) {

out.write(len); //此时也可以用:IOUtils.copyBytes(in,out,conf);

}

in.close();

out.close();

}catch(Exception e) {

e.printStackTrace();

}finally {

if(in != null) {

try {

in.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

if (out != null) {

try {

out.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

FileSystem方法——获取功能——获取到某文件的输入流——读取文件

方法

public FSDataInputStream open(Path f) throws IOException

public abstract FSDataInputStream open(Path f,int bufferSize)throws IOException

使用——将hdfs中的1.jpg拷贝到本地E:/hzy2.jpg

try {

//创建与HDFS连接

Configuration conf = new Configuration();

conf.set("fs.defaultFS","hdfs://10.9.190.90:9000");

//获得fileSystem

FileSystem fileSystem = FileSystem.get(conf);

//获取hdfs文件输入流

FSDataInputStream in = fileSystem.open(new Path("/1.jpg"));

//获取本地输出流

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File("E:/hzyCopy.jpg")));

int len = 0;

byte[] bArr = new byte[1024*3];

while((len = in.read(bArr)) != -1) {

out.write(bArr,0,len);

}

in.close();

out.close();

}catch(Exception e) {

e.printStackTrace();

}

}

FileSystem方法——创建功能

public boolean mkdirs(Path f) throws IOException

FileSystem方法——删除功能

public abstract boolean delete(Path f,boolean recursive) throws IOException

设计线程同步问题

FileSystem方法——重命名功能

public abstract boolean rename(Path src,Path dst)throws IOException

FileSystem其他方法

public void concat(Path trg,Path[] psrcs)throws IOException

Concat existing files together.

public boolean truncate(Path f,long newLength)throws IOException

interface RemoteIterator

定义

public interface RemoteIterator {

boolean hasNext() throws IOException;

E next() throws IOException;

}

The primary use of RemoteIterator in the filesystem APIs is to list files on (possibly remote) filesystems.

使用

//listLocatedFileStatus(Path f)

public org.apache.hadoop.fs.RemoteIterator listLocatedStatus(Path f)

throws FileNotFoundException,IOException

//listLocatedStatus(Path f,PathFilter filter)

protected org.apache.hadoop.fs.RemoteIterator listLocatedStatus(Path f,PathFilter filter)

throws FileNotFoundException,IOException

//listStatusIterator(Path p)

public org.apache.hadoop.fs.RemoteIterator listStatusIterator(Path p)

throws FileNotFoundException,IOException

//listFiles(Path f,boolean recursive)

public org.apache.hadoop.fs.RemoteIterator listFiles(Path f,boolean recursive)

throws FileNotFoundException,IOException

interface StreamCapabilities

方法

public interface StreamCapabilities {

boolean hasCapability(String capability);

}

使用

hadoop2.7.3中无此方法,在2.9.1中才有

hdfs user 连接_通过API访问HDFS相关推荐

  1. Java API访问HDFS集群(HA)

    title: Java API访问HDFS集群(HA) date: 2021-06-23 17:06:11 tags: HDFS hadoopV2版本及以后都是HA架构,active namenode ...

  2. java hdfs文件_使用Java访问HDFS中的文件

    我试图使用Java API访问HDFS中的文件,但每次我都找不到文件.我用来访问的代码是: – Configuration conf = new Configuration(); conf.addRe ...

  3. python读取hadoop库数据_使用Python访问HDFS

    最近接触到大数据,对于Skpark和Hadoop的料及都停留在第一次听到这个名词时去搜一把看看大概介绍免得跟不上时代的层次. 在实际读了点别人的代码,又自己写了一些之后,虽然谈不上理解加深,至少对于大 ...

  4. java获取hdfs总大小_如何获取出HDFS已用空间/总空间的值。java FileSystem中有相关的方法吗???...

    展开全部 public List getHdfsstatus() { if (conf == null) { conf = new Configuration(); conf.set("fs ...

  5. Java API 访问HA模式下的HDFS集群

    在使用Hadoop Java API访问HDFS集群时,在创建FileSystem对象时,直接指定NameNode的IP以及端口号即可.但是在HA模式下,访问HDFS集群却有一些不同,需要指定Name ...

  6. 实验二 HDFS的Shell命令操作,和HDFS的API操作

    文章目录 实验目的 一. 实验原理 二.实验准备 实验内容 步骤 项目1 HDFS常见命令练习 列出HDFS当前用户家目录下的文件及文件夹: 列出HDFS文件下名为directory的文件夹中的文件: ...

  7. Java 访问 HDFS操作

    Java 可以通过API访问HDFS, 主要用到几个类 下面是代码 package com.shidai.hadoop.hdfs01;import java.io.File; import java. ...

  8. Hadoop通过路径和和链接访问HDFS

    如果既想在Hadoop服务器本地可以通过绝对路径如"/user/hadoop"方式访问hdfs,也想通过"hdfs://local host:9000/user/hado ...

  9. hdfs 数据迁移_对象存储BOS发布全新工具,加速自建HDFS到云端的访问速度

    想让自建Hadoop拥有流畅的云端访问体验?想替老板省点钱?是时候升级你的装备了! 百度智能云对象存储服务BOS新推出BOS HDFS工具,支持HDFS数据在BOS中的海量存储,并能在上层数据运算中使 ...

最新文章

  1. SQL SERVER中架构的理解
  2. EXP-00091 正在导出有问题的统计信息 问题的解决(转)
  3. PYTHON 爬虫笔记七:Selenium库基础用法
  4. SOA对微服务的残余影响
  5. 基于OpenGL编写一个简易的2D渲染框架-07 鼠标事件和键盘事件
  6. C# ASP.NET WebApi入门
  7. 一个优秀的硬件工程师要具备的能力
  8. PDF打开时显示“正在准备文档以供阅读
  9. 福特汉姆大学计算机科学专业,福特汉姆大学计算机科学排名第131(2018年TFE美国排名)...
  10. window7安装过后有多大?6.18G
  11. cpc和ocpc,如果你是运营,你选哪个?
  12. java项目实战-超市管理系统(三)页面设计源码
  13. HDMI光纤线,英文称呼:hdmi AOC Cable,又被称为有源光缆。
  14. 几类自适应波束形成算法推导
  15. SIMPLE算法求解多孔介质的一维流动控制方程
  16. mongodb pymongo
  17. 北京功略----购物篇
  18. redis如何清空缓存
  19. Java最全截取字符串方法
  20. 个人seo的经验分享

热门文章

  1. Spring could 使用Feign超时问题
  2. ubuntu server 16.10 启用无线网卡
  3. bootstrap-进度条
  4. Oracle调用接口(OCI)源码剖析(2):执行SQL语句并获取结果
  5. 外部排序---置换选择+败者树
  6. metasploit篇-01
  7. 开启MySQL的sql语句记录
  8. 14c语言课程设计题目,2011级数据库课程设计任务书
  9. 【ABAP】获取程序中的Include
  10. Hybris 体系结构