/** delete a dir in the hdfs
*
* dir may like '/tmp/testdir'
*/
public static void deleteDir(String dir) throws IOException
{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
fs.delete(new Path(dir));
fs.close();
}
2.3 读取某个目录下的所有文件
public static void listAll(String dir) throws IOException
{
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
FileStatus[] stats = fs.listStatus(new Path(dir));
for(int i = 0; i < stats.length; ++i)
{
if (stats[i].isFile())
{
// regular file
System.out.println(stats[i].getPath().toString());
}
else if (stats[i].isDirectory())
{
// dir
System.out.println(stats[i].getPath().toString());
}
else if(stats[i].isSymlink())
{
// is s symlink in linux
System.out.println(stats[i].getPath().toString());
}
}
fs.close();
}