我的hadoop-1.2.1配置很糟糕:

***core-site.xml***

<configuration>
    <property>
        <name>fs.default.name</name>
        <value>hdfs://localhost:9000</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/home/dsk/hadoop/tmp-storage</value>
    </property>
</configuration>


***hdfs-site.xml***


<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
</configuration>

我想使用Hadoop Filesystem API在HDFS中开辟新的方向 . 所以我在我的代码中写道:

@Test
    public void testDirectory() throws Exception {

        Configuration configuration = new Configuration();
        FileSystem hdfs = HDFSUtils.getFileSystem(configuration);
        Path path = new Path("/test_dir");
        boolean isSuccess = hdfs.mkdirs(path);
        System.out.println("mkdir   test_dir" + (isSuccess ? " success" : " failure"));
    }

我的 class HDFSUtils 是:

public static FileSystem getFileSystem(Configuration conf) {

        FileSystem hdfs = null;
        try {

            hdfs = FileSystem.get(conf);
            return hdfs;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return hdfs;
    }

我想要我的hdfs层次结构,如下所示:
enter image description here
但是当我使用JUnit进行测试时,我得到了 mkdir test_dir failure .

我工作的IDE是Eclipse,在 conf 文件夹中包含两个 xml 文件
enter image description here

关于如何使用Filesystem API操作HDFS上的文件仍然存在一些问题 . 起初我使用了 URL 方法,它起作用了 .

String fileUrl = "hdfs://localhost:9000/firstSQL.sql";

但当我将其更改为HDFS FileSystem API时,我找不到我的文件:

Configuration conf = new Configuration();
    FileSystem hdfs = HDFSUtils.getFileSystem(conf);
    Path path = new Path("/firstSQL.sql");

失败痕迹是 java.io.FileNotFoundException: File /firstSQL.sql does not exist.

但我确实在HDFS中有 firstSQL.sql .
enter image description here

我对HDFS上的 real path of my file 感到困惑 .