For HDFS operations, you can use Hadoop FS commands, but also use Java to operate, the following small example, is a brief introduction of the Java Operation HDFs files, etc...
Package com.hdfs.nefu;/** * @auther XD **/import java.io.fileinputstream;import java.io.ioexception;import Java.net.uri;import Java.net.urisyntaxexception;import Org.apache.hadoop.conf.configuration;import Org.apache.hadoop.fs.fsdatainputstream;import Org.apache.hadoop.fs.fsdataoutputstream;import Org.apache.hadoop.fs.filesystem;import Org.apache.hadoop.fs.path;import Org.apache.hadoop.io.ioutils;public Class App {final static string url = "Hdfs://localhost/hello"; final static string Dir_path = "d1/1000"; final static string File_ Path = "d1/1000/f100";p ublic static void Main (string[] args) throws IOException, urisyntaxexception {/*** load file HDFs streaming data so in I need to get the input and output stream when the operation is done * The HDFS operation is only required to obtain the FileSystem object **/final FileSystem FileSystem = Filesystem.get (The new URI (URL), as shown in the following code. New Configuration ()); Create folder mkdir (filesystem);/* Upload a file As long as this file exists, create a file to form an output stream */final fsdataoutputstream out = filesystem.create (New Path ( File_path)); final FileInputStream in = new FileInputStream ("D:\\log.txt"); Uploaddata (The download file requires a file to be opened before it can be downloaded final fsdatainputstream input = Filesystem.open (new Path (File_path));d ownloaddata (input );//Delete folder DeleteFile (filesystem);} /* The following methods simply extract the refactoring method by using shortcut keys * Use shortcut keys where they are called: Alt+shift+m the following situation occurs */private static void DeleteFile (final FileSystem FileSystem) Throws IOException {filesystem.delete (new Path (File_path), true);} private static void Downloaddata (final fsdatainputstream input) throws IOException {ioutils.copybytes (input, System.out , 1024x768, true);} private static void Uploaddata (final fsdataoutputstream out,final FileInputStream in) throws IOException { Ioutils.copybytes (in, out, 1024x768, true);} private static void mkdir (final FileSystem FileSystem) throws IOException {filesystem.mkdirs (new Path (Dir_path));}}
HDFs file Operations (Java code Implementation)