Log4j:warn No Appenders could is found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
Log4j:warn Initialize the log4j system properly.
Log4j:warn See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.IllegalArgumentException: wrong Fs:hdfs://sandbox.hortonworks.com:8020/user /testdir, expected:file:///
At Org.apache.hadoop.fs.FileSystem.checkPath (filesystem.java:645)
At Org.apache.hadoop.fs.RawLocalFileSystem.pathToFile (rawlocalfilesystem.java:80)
At Org.apache.hadoop.fs.RawLocalFileSystem.mkdirs (rawlocalfilesystem.java:423)
At Org.apache.hadoop.fs.ChecksumFileSystem.mkdirs (checksumfilesystem.java:590)
At Com.hdfs.directory.CreateDir.main (createdir.java:19)
Running on this machine will cause the above error to be changed to the following code:
Packagecom.hdfs.directory;Importjava.io.IOException;Importorg.apache.hadoop.conf.Configuration;ImportOrg.apache.hadoop.fs.FileSystem;ImportOrg.apache.hadoop.fs.Path; Public classCreatedir {/** * @paramargs *@throwsIOException*/ Public Static voidMain (string[] args)throwsIOException {//TODO auto-generated Method StubConfiguration conf=NewConfiguration (); Path NewPath=NewPath ("Hdfs://sandbox.hortonworks.com:8020/user/testdir"); //FileSystem fs=filesystem.get (conf);FileSystem fs =newpath.getfilesystem (conf); Fs.mkdirs (NewPath); Fs.close ();//filestatus Filestatus=fs.getfilestatus (New Path ("/user/long1657/20130908")); }}
or Hadoop-related configuration information, placed in the project directory:
After executing the above code: the/user/testdir directory was successfully deleted:
After you add a Hadoop-related configuration file to your project, you can create the folder successfully with the following code:
Packagecom.hdfs.directory;Importjava.io.IOException;Importorg.apache.hadoop.conf.Configuration;ImportOrg.apache.hadoop.fs.FileSystem;ImportOrg.apache.hadoop.fs.Path; Public classcreatedirwithconf {/** * @paramargs *@throwsIOException*/ Public Static voidMain (string[] args)throwsIOException {//TODO auto-generated Method StubConfiguration conf=NewConfiguration (); FileSystem FS=filesystem.get (conf); Fs.mkdirs (NewPath ("Hdfs://sandbox.hortonworks.com:8020/user/testdir")); Fs.close ();//filestatus Filestatus=fs.getfilestatus (New Path ("/user/long1657/20130908")); }}
Hadoop Create/Delete folder error