HDFS的Java访问接口


得到filesystem的实例
有两个静态方法可以得到filesystem接口的实例
public static FileSystem get(Configuration conf) throws IOException
public static FileSystem get(URI uri, Configuration conf) throws IOException
第一个方法得到缺省的文件系统,具体由配置文件的fs.default.name属性决定。
第二个方法由URI的前缀决定是哪个文件系统(参考前一篇文章),如果URI没有前缀也是得到缺省的文件系统。
使用open方法得到文件的输入流
有了filesystem的实例,我们就可以调用open方法得到一个文件的输入流了
public FSDataInputStream open(Path f) throws IOException
public abstract FSDataInputStream open(Path f, int bufferSize) throws IOException
第一个方法用缺省的buffer大小4K
使用FSDataInputStream读数据
FSDataInputStream派生自java.io.DataInputStream,支持随机读取。
public class FSDataInputStream extends DataInputStream
    implements Seekable, PositionedReadable {
    void seek(long pos) throws IOException;
    public int read(long position, byte[] buffer, int offset, int length) throws IOException;
}
使用FSDataOutputStream写数据
filesystem接口创建文件的接口
public FSDataOutputStream create(Path f) throws IOException
还可以append到一个已经存在的文件
public FSDataOutputStream append(Path f) throws IOException
public class FSDataOutputStream extends DataOutputStream implements Syncable {
   public void write(int b) throws IOException;
   public void write(byte b[], int off, int len) throws IOException;
}
filesystem的文件系统操作方法
public boolean mkdirs(Path f) throws IOException ;
public void copyToLocalFile(boolean delSrc, Path src, Path dst) throws IOException;
public abstract boolean delete(Path f, boolean recursive) throws IOException;
public abstract boolean rename(Path src, Path dst) throws IOException;
public abstract FileStatus[] listStatus(Path f) throws IOException;
本文来自CSDN博客,转载请标明出处: http://blog.csdn.net/fiberlijun/archive/2009/11/16/4814647.aspx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值