2011年4月18日 星期一

Read a file in HDFS

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FSDataOutputStream;

首先 先建立一個FileSystem物件,在建立此物件時,必需傳入一個Configuration object,因此
我們先Create一個Configuration object
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
之後就可以用這個 FileSystem object來開檔,創出一個FSDataInputStream object
Path inFile = new Path("/tmp/test");
FSDataInputStream in = fs.open(outFile);

之後就用
in.read(long position, byte[] buffer, int offset, int length)
in.readFully(long position, byte[] buffer)

來讀檔


沒有留言:

張貼留言