You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Deyaa Adranale <de...@iais.fraunhofer.de> on 2008/05/20 17:17:15 UTC
reading a directory children in DFS?
hello,
i have a problem in reading the children of a directory in the
distributed file system of hadoop:
when I read the results of the reduce, I know the output folder (which i
have specified using JobConf), but I don't know the file names inside
it, and i still does not know how to access them using Java code
I have tried this:
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
String outputDir = ....
Path inDir = new Path("");
if (!fs.exists(inDir))
throw new Exception("Directory does not exist");
File jInDir = new RawLocalFileSystem().pathToFile(inDir);
String[] files = jInDir.list();
for (int i=0; i<files.length; i++) {
Path inFile = new Path(inDir, files[i]);
but the files array is null, and i get a null pointer exception when
files.length.
any suggestions? I have searched on the internet, wiki and the archive,
but could not find something useful.
thanks for the help
Deyaa
Re: reading a directory children in DFS?
Posted by Hairong Kuang <ha...@yahoo-inc.com>.
Your code is trying to list a directory in the local file system. You should
use the dfs handler instead.
Path[] children =
FileUtil.status2paths(dfs.listStatus(parentDirectoryPath));
Hairong
On 5/20/08 8:17 AM, "Deyaa Adranale" <de...@iais.fraunhofer.de>
wrote:
> hello,
> i have a problem in reading the children of a directory in the
> distributed file system of hadoop:
> when I read the results of the reduce, I know the output folder (which i
> have specified using JobConf), but I don't know the file names inside
> it, and i still does not know how to access them using Java code
> I have tried this:
>
> Configuration conf = new Configuration();
> FileSystem fs = FileSystem.get(conf);
>
> String outputDir = ....
> Path inDir = new Path("");
>
> if (!fs.exists(inDir))
> throw new Exception("Directory does not exist");
>
> File jInDir = new RawLocalFileSystem().pathToFile(inDir);
> String[] files = jInDir.list();
> for (int i=0; i<files.length; i++) {
> Path inFile = new Path(inDir, files[i]);
>
>
>
> but the files array is null, and i get a null pointer exception when
> files.length.
>
> any suggestions? I have searched on the internet, wiki and the archive,
> but could not find something useful.
>
>
> thanks for the help
>
> Deyaa