hadoop读取文件内容


/**
* @see 读取dst文件内容
* @param dst
* @return
* @throws Exception
*/
public static byte[] readHDFSFile(String dst) throws Exception
{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);

// check if the file exists
Path path = new Path(dst);
if ( fs.exists(path) )
{
FSDataInputStream is = fs.open(path);
// get the file info to create the buffer
FileStatus stat = fs.getFileStatus(path);

// create the buffer
byte[] buffer = new byte[Integer.parseInt(String.valueOf(stat.getLen()))];
is.readFully(0, buffer);

is.close();
fs.close();

return buffer;
}
else
{
throw new Exception("the file is not found .");
}
}

你可能感兴趣的:(hadoop,hadoop,java)