/** read the hdfs file content
* notice that the dst is the full path name
*/
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 .");
}
}
2.1 创建目录
/** make a new dir in the hdfs
*
* the dir may like '/tmp/testdir'
*/
public static void mkdir(String dir) throws IOException
{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
fs.mkdirs(new Path(dir));
fs.close();
}
2.2 删除目录